Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autosize UILabel

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.

like image 729
Yolanda Avatar asked Jul 14 '10 07:07

Yolanda


People also ask

What is UILabel?

A view that displays one or more lines of informational text.

How to increase label size according to text in ios?

Just use auto layout to add constraints to pin the left and top sides of the label. After that it will automatically resize.

How do you text the height of UILabel?

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.

How do I change the size of labels in Xcode?

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.


1 Answers

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.

like image 107
jergason Avatar answered Oct 05 '22 15:10

jergason