I have a UILabel that displays some chars. Like "x", "y" or "rpm". How can I calculate the width of the text in the label (it does not ues the whole available space)? This is for automatic layouting, where another view will have a bigger frame rectangle if that UILabel has a smaller text inside. Are there methods to calculate that width of the text when a UIFont and font size is specified? There's also no line-break and just one single line.
Iphone – How to calculate the width of a text string of a specific font and font-size
cocoa-touchiphoneuikit
Related Topic
- Objective-c – Pixel Width of the text in a UILabel
- Iphone – How to calculate the size of a UIFont when text in label is constrained down to fit width
- Javascript – undefined is not an object firebase.auth.FacebookAuthProvider.credential
- Ios – Multiline UILabel with adjustsFontSizeToFitWidth
- Ios – How to get the screen width and height in iOS
- Ios – UILabel is not auto-shrinking text to fit label size
- Ios – How to calculate actual font point size in iOS 7 (not the bounding rectangle)
Best Answer
Since
sizeWithFont
is deprecated, I'm just going to update my original answer to using Swift 4 and.size
The size should be the onscreen size of "Your Text Here" in points.