masonry高级用法

一  cell中masonry中用法

1  使用 [_templateCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]。

2  根据cell最下面的控件的底部。

3  UITableViewAutomaticDimension

4 只会重新计算高度,不会reload cell,所以只是把原来的cell撑大了而已,还是同一个cell实例

[_tableView beginUpdates];[_tableView endUpdates];

二 label约束高级使用

[_label1 setContentHuggingPriority:UILayoutPriorityRequired

forAxis:UILayoutConstraintAxisHorizontal];

//设置label1的content compression 为1000

[_label1 setContentCompressionResistancePriority:UILayoutPriorityRequired

forAxis:UILayoutConstraintAxisHorizontal];

//设置右边的label2的content hugging 为1000

[_label2 setContentHuggingPriority:UILayoutPriorityRequired

forAxis:UILayoutConstraintAxisHorizontal];

//设置右边的label2的content compression 为250

[_label2 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow

forAxis:UILayoutConstraintAxisHorizontal];

三  等间距

UIView *lastSpaceView = [UIView new];

lastSpaceView.backgroundColor = [UIColor greenColor];

[_containerView1 addSubview:lastSpaceView];

[lastSpaceView mas_makeConstraints:^(MASConstraintMaker *make) {

make.left.and.top.and.bottom.equalTo(_containerView1);

}];

for (NSUInteger i = 0; i < ITEM_COUNT; i++) {

UIView *itemView = [self getItemViewWithIndex:i];

[_containerView1 addSubview:itemView];

[itemView mas_makeConstraints:^(MASConstraintMaker *make) {

make.height.and.width.equalTo(@(ITEM_SIZE));

make.left.equalTo(lastSpaceView.mas_right);

make.centerY.equalTo(_containerView1.mas_centerY);

}];

UIView *spaceView = [UIView new];

spaceView.backgroundColor = [UIColor greenColor];

[_containerView1 addSubview:spaceView];

[spaceView mas_makeConstraints:^(MASConstraintMaker *make) {

make.left.equalTo(itemView.mas_right).with.priorityHigh(); // 降低优先级,防止宽度不够出现约束冲突

make.top.and.bottom.equalTo(_containerView1);

make.width.equalTo(lastSpaceView.mas_width);

}];

lastSpaceView = spaceView;

}

[lastSpaceView mas_makeConstraints:^(MASConstraintMaker *make) {

make.right.equalTo(_containerView1.mas_right);

}];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容