美文网首页
cell高度根据内容来变化

cell高度根据内容来变化

作者: EncourageMan | 来源:发表于2017-03-20 15:24 被阅读0次

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

_removeHeight = [SystermTableViewCell setHeightForRow:_model.data[indexPath.section][@"description"]];

return _removeHeight;

}

+(CGFloat)setHeightForRow:(NSString *)str{

CGFloat textHeight = [[DataManager shareDataManager] getHeightOfText:str fontOfText:[UIFont systemFontOfSize:14*ratew] widthOfText:kScreenW-20];

CGFloat rowHeight =textHeight+32+45;

return rowHeight;

}

//得到文本高度

-(CGFloat)getHeightOfText:(NSString *)text fontOfText:(UIFont *)font widthOfText:(CGFloat)width{

CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAX_CANON) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];

return rect.size.height>21.0 ? rect.size.height : 21.0;

}

相关文章

网友评论

      本文标题:cell高度根据内容来变化

      本文链接:https://www.haomeiwen.com/subject/gyydnttx.html