I have a UILabel that wraps words correctly if I make its frame height high enough. However, I want it to dynamically find the desired height, and the method sizeWithFontdoes not; this method just creates a single line in my label:
CGSize subtitleSize=[subtitle sizeWithFont:subtitleFont forWidth:maxwidth lineBreakMode:UILineBreakModeWordWrap];
Then I use the same text, font and size from this function:
UILabel *subLabel=[[[UILabel alloc] initWithFrame:CGRectMake(0, 0, maxwidth, subtitleSize.height)]autorelease];
subLabel.font=subtitleFont;
subLabel.text=subtitle;
subLabel.numberOfLines=0;
subLabel.lineBreakMode=UILineBreakModeWordWrap;
It seems like everything should work and give me the size that I then use. But the height of the size is always equal to one line for the label.
source
share