M A M A - 5 months ago 27
Swift Question

Swift: Getting a string width to make a frame (using CGRect) in swift 2.2

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 :-