首页 > 代码库 > UILabel 自动高度计算

UILabel 自动高度计算

#pragma mark UILabel 自动高度计算
- ( void ) labelAutoHeight:(UILabel *) contentLabel:(NSString *) text {
     
     UIFont *font = [UIFont systemFontOfSize:12];
     contentLabel.font = font;
     [contentLabel setNumberOfLines:0];
     contentLabel.lineBreakMode = UILineBreakModeWordWrap;
     contentLabel.backgroundColor = [UIColor greenColor];
     contentLabel.tag = 102;
     CGSize size = CGSizeMake(320,2000);
     CGSize labelsize = [text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
     [contentLabel setFrame:CGRectMake(20, 30, 320, labelsize.height)];
}
 
// 调用方式
<p>
     [<span>self</span> <span>labelAutoHeight</span>:contentLabel:text];
</p>


UILabel 自动高度计算