How can I get width of a string in swift 2.2 and iOS 9 ?
What I want to do is to create a UIButton programmatically but its frame needs to fit the title size which will be inferred at runtime.
Note: We know frame's height.
After you have set the text of button just call :-
yourButton.sizeToFit()