M A M A - 1 year ago 152
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.

Answer Source

After you have set the text of button just call :-


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download