In interface builder, holding Command + = will resize a button to fit its text. I was wondering if this was possible to do programmatically before the
sizeToFit doesn't work correctly. instead:
myButton.size = myButton.sizeThatFits(CGSize.zero)
you also can add contentInset to the button:
contentInset
myButton.contentEdgeInsets = UIEdgeInsetsMake(8, 8, 4, 8)