I have the following layout, and I\'m trying to add a padding to the left and right..
The controls are a disabled UIButton.
You can also set the inset values from the Interface Builder Size Inspector inside a Storyboard or xib.
I found an easy/hacky way to add borders to text buttons (and have left/right margins):
Create button with title.
Place button in storyboard, align where you want and then add a forced width constraint that is an even number (I used 20, so it adds 10 points on each side). This will force the border around the width you created.
Use code to create a border. eg:
myTextButton.backgroundColor = .clear
myTextButton.layer.cornerRadius = 5
myTextButton.layer.borderWidth = 2
myTextButton.layer.borderColor = UIColor.white.cgColor
Set left titleInset to 2 via editor (now under Size Inspector) or by code. This seems to center the text, but this value may be different for various texts and text sizes.
This post is for Xcode 8.1 and Swift 3.
With the above solutions, some of the text were cut out if you have a border around the button. For instance, a button label named "Delete something" ends up showing "Dele...ing". If you are having this problem, this is the solution:
aButton.contentEdgeInsets = UIEdgeInset.init(top: 0, left: 8, bottom: 0, right: 8)