Cell高度自适应
2017-06-06 本文已影响43人
MrSong
Cell高度自适应
@(iOS)[UITableView]
这是找到的最简单一种自适应方法了,代码量不多
- 1、首先要在set模型时候将高度计算出来,更新cell布局
- 2、然后再tableView代理方法中拿到这个cell去更新高度,主要是这个方法
- (void)setCheckModel:(MMKeyPlacesVisitAgainCheckAreaModel *)checkModel {
_checkModel = checkModel;
self.titleLable.text = checkModel.name;
CGSize size = [self sizeString:checkModel.name WithFont:[UIFont systemFontOfSize:FontSize] constrainedToSize:CGSizeMake(ScreenWidth, MAXFLOAT)];
self.titleLable.frame = CGRectMake(0, 0, ScreenWidth, size.height >= 40 ?:40);
self.yesLable.frame = CGRectMake(0, _titleLable.SLQBottom, 20, 40);
self.yesBtn.frame = CGRectMake(_yesLable.SLQRight , _titleLable.SLQBottom, 40, 40);
self.noLable.frame = CGRectMake(_yesBtn.SLQRight , _titleLable.SLQBottom, 20, 40);
self.noBtn.frame = CGRectMake(_noLable.SLQRight, _titleLable.SLQBottom, 40, 40);
self.SLQHeight = self.noBtn.SLQBottom;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}