Autosize UILabel

Yolanda picture Yolanda · Jul 14, 2010 · Viewed 14.2k times · Source

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.

Answer

jergason picture jergason · Jul 14, 2010

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.