Multi-line UILabel adjustFontSizeToFitWidth

Discussion in 'iPhone/iPad Programming' started by admanimal, Aug 23, 2008.

  1. macrumors 68040

    Joined:
    Apr 22, 2005
    #1
    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

    Joined:
    Sep 30, 2008
    Location:
    Hyderabad,India
    #2
    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
    siva.d
     
  3. macrumors 68030

    PhoneyDeveloper

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

    Joined:
    Feb 12, 2008
    Location:
    Illinois
    #4
    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

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    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