美文网首页
UITableViewCell自适应高度

UITableViewCell自适应高度

作者: 小热带雨林 | 来源:发表于2020-04-05 12:19 被阅读0次
很多情况是cell的高度根据内容的高度改变而改变的

如图


屏幕快照 2020-04-05 12.14.12.png

cell的高度是根据图片与状态文字内容进行确定的,故不能设置固定高度
1.设置预估行高

    self.tableViwe.estimatedRowHeight = 200;
    self.tableViwe.rowHeight = UITableViewAutomaticDimension;

2.自定义cell

[self.tableViwe registerClass:[ZFBMomentCell class] forCellReuseIdentifier:cellID];

3.自定义cell中从顶部一致到底部所有的子控件设置相关的约束

//最关键的一个子控件的约束,需要设置相对于contentView底部的约束,将整个cell撑开
  [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pictureView.mas_bottom).offset(8);
        make.left.equalTo(self.pictureView);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-8);
    }];

相关文章

网友评论

      本文标题:UITableViewCell自适应高度

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