UIButton Text Margin / Padding

Setting the content insets will prevent the UIButton's title to shrink or truncated, giving the text margin a padding.

content edges


// Swift
var titleEdgeInsets: UIEdgeInsets!

// Objective-C
@property(nonatomic) UIEdgeInsets titleEdgeInsets;

Use this property to resize and reposition the effective drawing rectangle for the button title. You can specify a different value for each of the four insets (top, left, bottom, right). A positive value shrinks, or insets, that edge—moving it closer to the center of the button. A negative value expands, or outsets, that edge. Use the UIEdgeInsetsMake function to construct a value for this property. The default value is UIEdgeInsetsZero.

https://developer.apple.com/documentation/uikit/uibutton/1624010-titleedgeinsets


You can also set the inset values from the Interface Builder Size Inspector inside a Storyboard or xib.

Interface Builder Size Inspector