#pragma mark UILabel 自动高度计算 |
02 | - ( void ) labelAutoHeight:(UILabel *) contentLabel:(NSString *) text { |
03 | |
04 | UIFont *font = [UIFont systemFontOfSize:12]; |
05 | contentLabel.font = font; |
06 | [contentLabel setNumberOfLines:0]; |
07 | contentLabel.lineBreakMode = UILineBreakModeWordWrap; |
08 | contentLabel.backgroundColor = [UIColor greenColor]; |
09 | contentLabel.tag = 102; |
10 | CGSize size = CGSizeMake(320,2000); |
11 | CGSize labelsize = [text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap]; |
12 | [contentLabel setFrame:CGRectMake(20, 30, 320, labelsize.height)]; |
13 | } |
14 |
15 | // 调用方式 |
16 | <p> |
17 | [<span>self</span> <span>labelAutoHeight</span>:contentLabel:text]; |
18 | </p> |