cell高度根据内容来变化

2017-03-20  本文已影响0人  EncourageMan

- (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;

}

上一篇 下一篇

猜你喜欢

热点阅读