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布局

label布局

button布局

备注:
如果有不足或者错误的地方还望各位读者批评指正,可以评论留言,笔者收到后第一时间回复。
QQ/微信:976971956/ljh976971956。
简书号:超级卡布达
感谢各位观众老爷的阅读,如果觉得笔者写的还凑合,可以关注或收藏一下,不定期分享一些好玩的实用的demo给大家。
文/超级卡布达(简书作者)
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
网友评论