0

If we put too much text, UILabel would shrink the texts.

Sometimes we put 4 lines in a text. Sometimes there are 20 lines in a text. Sometimes there are none.

Also text may be short or long.

How to make UILabel to fit the amount of that texts?

Also how to to make UIView that encompass that UILabel to also fit the larger or smaller UILabel?

4

1 回答 1

2

Use the UIKit Additions to NSString to determine the size of a text with a given font.

NSString *myLongText = @"......" // some long text.
UIFont *font = [UIFont systemFontOfSize:12];
CGSize size = [myLongText sizeWithFont:font 
                              forWidth:maxWidth
                         lineBreakMode:NSLineBreakByWordWrapping];
myLabel.frame = (CGRect){myLabel.frame.origin, size};
于 2012-10-22T15:02:21.987 回答