Multi-line UILabel adjustFontSizeToFitWidth

Discussion in 'iOS Programming' started by admanimal, Aug 23, 2008.

  1. macrumors 68040

    Apr 22, 2005
    Has anyone figured out how to get the auto font size adjustment to work for a UILabel when it has numberOfLines set to more than one? It seems to just ignore adjustFontSizeToFitWidth if the label has more than one line.
  2. macrumors newbie

    Sep 30, 2008
    I also need this can any one help

    Thanks in advance,

    I want to display text in more than one line, can any one help me.

    Thank you
  3. macrumors 68030


    Sep 2, 2008
    Did you read the comment in UILabel.h where it says that adjustsFontSizeToFitWidth only works if lineCount is 1?
  4. macrumors 68000

    Feb 12, 2008
    So in other words, you'll have to use a UITextView which has a dynamic number of lines but fixed font size.
  5. macrumors 68030


    Sep 2, 2008
    Dynamic number of lines with a fixed font size is exactly what UILabel gives you if you set the numberOfLines to zero. The usual reason to use adjustsFontSizeToFitWidth is if you have a fixed size for the label and you want all the text to fit. If you can allow the label to be any height then you don't need that.

    Also you could probably use sizeWithFont:constrainedToSize:lineBreakMode to find the font size that will show all the text in a multiline label and then set that font size for the label.

Share This Page