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);

}];

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容