根据约束适配cell高度。不用实现- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 方法
cell.m
- (void)masMake {
[self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView);
make.top.equalTo(self.contentView).offset(leftPadding * 2);
make.height.mas_equalTo(20);
}];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.detailLab.mas_bottom).offset(leftPadding * 2);
make.left.equalTo(self.contentView).offset(leftPadding/2.0);
make.right.equalTo(self.contentView).offset(-leftPadding/2.0);
make.bottom.equalTo(self.contentView);
make.height.mas_greaterThanOrEqualTo(20);
}];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(leftPadding);
make.right.equalTo(self.contentView).offset(-leftPadding);
make.top.equalTo (self.bgView).offset(leftPadding);
make.bottom.equalTo(self.imgView.mas_top);
make.height.mas_greaterThanOrEqualTo(20);
}];
//图片
[self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLab);
make.right.equalTo(self.titleLab);
make.bottom.equalTo(self.bgView).offset(- leftPadding);
make.height.mas_greaterThanOrEqualTo(0);
}];
}
tableView里设置
_tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.estimatedRowHeight = 100;