您的位置:首页 > 移动开发 > IOS开发

ios根据内容设置cell的高度

2016-07-18 16:21 423 查看
基本思路是:先获取该行要显示的文本内容,根据文本计算行高

// 根据文本高度来设置cell高度
-(CGFloat)tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *textArray = [_textArray objectAtIndex:indexPath.row];
NSDictionary *attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:15.0]};
CGSize textSize1 = [textArray boundingRectWithSize:CGSizeMake(ViewWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:attribute context:nil].size;

return textSize1.height+35;//让文本离cell有一定的距离显示,上7.5,下7.5

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: