Search code examples
iosobjective-cswiftuilabelautoresize

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.


Solution

  • 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.