//本帖为自用贴,不喜勿喷
-(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
{
UILabel*contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,
width, 0)];
[contentLabel setText:value];
contentLabel.font = [UIFont systemFontOfSize:fontSize];
contentLabel.numberOfLines=0;
contentLabel.textColor = [UIColor colorWithRed:27/255.0 green:27/255.0 blue:27/255.0 alpha:1];
// _contentLabel.backgroundColor=[UIColor greenColor];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:value];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//[paragraphStyle setLineSpacing:5];//调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [value length])];
contentLabel.attributedText = attributedString;
[contentLabel sizeToFit];
NSLog(@"textview:%f++",contentLabel.frame.size.height);
return contentLabel.frame.size.height;
}