标签:高度自适应 style io sp for strong on bs 代码
// 1. 核心代码
CGSize constraint = CGSizeMake(290, 20000.0f);
NSAttributedString *attributedText = [[NSAttributedStringalloc]initWithString:_contentLabel.textattributes:@{
NSFontAttributeName:[UIFontsystemFontOfSize:15]
}];
CGRect rect = [attributedText boundingRectWithSize:constraint
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
CGSize size = rect.size;
// 2. 设置frame
_contentLabel.frame = CGRectMake(10, 10, 290, size.height);
// 同时需要tableviewDelegate的方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ // 彩印内容
MyFavorCaiyinObject *myFavorCaiyin = _myFavorCaiyinModels[indexPath.row];
NSString *content = myFavorCaiyin.contentText;
// 动态设置cell的高度
// 1. 核心代码
CGSize constraint = CGSizeMake(290, 20000.0f);
NSAttributedString *attributedText = [[NSAttributedStringalloc]initWithString:content attributes:@{
NSFontAttributeName:[UIFontsystemFontOfSize:15]
}];
CGRect rect = [attributedText boundingRectWithSize:constraint
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
CGSize size = rect.size;
// 2. 设置高度
return size.height + 56;
标签:高度自适应 style io sp for strong on bs 代码
原文地址:http://www.cnblogs.com/liman1990/p/4122693.html