Reputation: 688
How to add a space before and after the text in UILabel using storyboard.
Here is an example of label with a background.
Upvotes: 0
Views: 1260
Reputation: 534925
One approach is:
Use auto layout in the storyboard.
Use a UILabel subclass that overrides intrinsicContentSize
to be a little wider than the default.
For example:
extension CGSize {
func sizeByDelta(dw dw:CGFloat, dh:CGFloat) -> CGSize {
return CGSizeMake(self.width + dw, self.height + dh)
}
}
class MyWiderLabel : UILabel {
override func intrinsicContentSize() -> CGSize {
return super.intrinsicContentSize().sizeByDelta(dw: 20, dh: 0)
}
}
Now just set the class of every label in your storyboard to be a MyWiderLabel.
Upvotes: 2