方法:
+(CGFloat)cellHeight:(NSString *)text{
//死值和文字的高度
return 20+60+10+20+[[self class]textHeight:text];
}
//计算文字的高度
+(CGFloat)textHeight:(NSString *)aString{
NSDictionary *dic=@{NSFontAttributeName:[UIFont systemFontOfSize:17]};
CGRect textRect=[aString boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-40, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
//只把高度返回
return textRect.size.height;
}
行数改为0
label.numberOfLines=0;
//获取label的frame
CGRect tempRect=cell.descriptionLabel.frame;
//改变高度
tempRect.size.height=[RootTableViewCell textHeight:stu.description];
//给label赋值
cell.descriptionLabel.frame=tempRect;