Is there a way to auto size a UILabel? given size 40 x 40 the text font size would adjust based on the number of characters.
A view that displays one or more lines of informational text.
Just use auto layout to add constraints to pin the left and top sides of the label. After that it will automatically resize.
text = text; label. numberOfLines = 0; [label sizeToFit]; return cell; Also use NSString 's sizeWithFont:constrainedToSize:lineBreakMode: method to compute the text's height. Show activity on this post.
You can set the Minimum Font Scale or size in Storyboard/Xib when you set it up in IB under the Attributes inspector. I prefer scale, as it is better at fitting longer text on iPhone 4/5/iPod touches. If you set the size, you can get cut off earlier than with scale.
You can use the adjustFontSizeToFitWidth
property. So something like this.
UILabel *myLabel = [[UILabel alloc] init];
[myLabel setAdjustsFontSizeToFitWidth:YES];
In Interface Builder there is a check box on the Label Attributes screen to allow you to adjust the font size to fit the label as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With