美文网首页iOS开发拾碎
UITableviewCell 使用Masonry撑开cell高

UITableviewCell 使用Masonry撑开cell高

作者: 王加水 | 来源:发表于2020-12-09 17:12 被阅读0次

1. 问题描述

在布局UITableviewCell 内容时, 可用使用Masonry方便的自动计算高度撑开布局,但是当遇到cell高度不同,多个复杂的子view竖向排列时,容易产生高度计算冲突问题导致报如下一坨

在这里插入图片描述

2. 解决办法

使用 MasonrypriorityHigh 属性来确定优先级

/**
 *  Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
 */
- (MASConstraint * (^)(void))priorityHigh;

具体使用要设置 <最后一个子view>bottom 属性 priorityHigh()

[self.lastView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.topView.mas_bottom).offset(5);
    make.left.equalTo(superView).offset(36);
    make.right.equalTo(superView).offset(-16);
    make.bottom.equalTo(self.contentView).offset(-16).priorityHigh();
}];

相关文章

网友评论

    本文标题:UITableviewCell 使用Masonry撑开cell高

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