UITableView和UICollectionView想通,此处就已UITableView为例
UITableView自带自适应属性
_tableView.rowHeight = UITableViewAutomaticDimension; _tableView.estimatedRowHeight = 130;
UITableViewCell中布局top和bottom需要布局,不然不会自适应
1.代码布局Masonry
[commentContent mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.contentView).offset(kMarginLeftSpacing); make.right.mas_equalTo(self.contentView).offset(-kMarginLeftSpacing); //上面 make.top.mas_equalTo(self.contentView).offset(kMarginTopSpacing); }];
[userNum mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.contentView).offset(-10); make.top.mas_equalTo(line.mas_bottom).offset(0); //下面 make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(0); make.height.mas_equalTo(43); }];
2.Autolayout布局
49FF058B-9D18-47A1-B580-04672CC5A8A2.png
label布局
image.png
button布局
image.png