masonry高級用法

一 ?cell中masonry中用法

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

2 ?根據(jù)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(); // 降低優(yōu)先級,防止寬度不夠出現(xiàn)約束沖突

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

}];

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容