實(shí)例化 redView 和 blueView
//實(shí)例化一個(gè)view
UIView *redView = [[UIView alloc]init];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
UIView *blueView = [[UIView alloc]init];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];
//masonry自動(dòng)幫我們把a(bǔ)utoresizing給禁用掉
設(shè)置 redView 和 blueView 的約束
// 設(shè)置redView的約束
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.left.offset(20);
// 針對topLayoutGuide進(jìn)行設(shè)置
// self.mas_bottomLayoutGuide 設(shè)置底部
// self.mas_topLayoutGuideBottom 設(shè)置頂部
make.top.equalTo(self.mas_topLayoutGuideBottom);
make.left.offset(20);
make.right.offset(20);
make.height.equalTo(@40);
}];
// 設(shè)置blueView的約束
/*
dividedBy: 除以
multipledBy:乘以
*/
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(redView.mas_bottom).offset(20);
make.right.offset(-20);
make.height.equalTo(redView);
// 寬度
// make.width.equalTo(redView).multipliedBy(0.5);
make.width.equalTo(redView).dividedBy(2);
}];
更新約束
// 更新約束
[redView mas_updateConstraints:^(MASConstraintMaker *make) {
// 更新redView的約束高度變?yōu)?0
make.height.equalTo(@80);
}];
重新設(shè)置約束
// 重新設(shè)置旁振,會(huì)把之前的約束給清空掉参淹,然后使用新的約束
[redView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.left.offset(20);
make.right.offset(-20);
make.height.equalTo(@80);
}];
設(shè)置約束的優(yōu)先級
// 設(shè)置約束的優(yōu)先級
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.offset(20);
make.right.offset(-20);
make.height.equalTo(@40).priority(10);
}];
/*
priority: 可以設(shè)置任意的優(yōu)先級涝焙,接受的參數(shù)是0-1000的數(shù)字
priorityLow: 設(shè)置低優(yōu)先級床未,優(yōu)先級為250
priorityMedium: 設(shè)置中優(yōu)先級,優(yōu)先級為500
priorityHigh: 設(shè)置高優(yōu)先級香伴,優(yōu)先級為750
需要注意的是,使用priorityLow、priorityMedium恒序、priorityHigh的時(shí)候。不是.priorityHigh谁撼,而是.priorityHigh()
*/