#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)];}// 调用方式
[self labelAutoHeight:contentLabel:text];