Masonry的优先级,更新,重置

//实例化一个view

UIView*redView = [UIViewnew];

redView.backgroundColor= [UIColorredColor];

[self.viewaddSubview:redView];

UIView*blueView = [UIViewnew];

blueView.backgroundColor= [UIColorblueColor];

[self.viewaddSubview:blueView];

//masonry自动帮我们把autoresizing给禁用掉


/**

更新约束

updateConstraints:

更新redView的约束高度变为80

[redView updateConstraints:^(MASConstraintMaker *make) {

make.height.equalTo(80);

}];

*/


/**

重新设置,会把之前的约束给清空掉,然后使用新的约束

remakeConstraints :

[redView remakeConstraints:^(MASConstraintMaker *make) {

make.top.left.offset(20);

make.right.offset(-20);

make.height.equalTo(80);

}];

*/


/**

设置约束的优先级

.priority(10)

[redView makeConstraints:^(MASConstraintMaker *make) {

make.top.left.offset(20);

make.right.offset(-20);

//make.height.equalTo(40).priorityLow();

make.height.equalTo(40).priority(10);

}];

[redView makeConstraints:^(MASConstraintMaker *make) {

make.height.equalTo(80).priority(20);

}];

*/


[redViewmakeConstraints:^(MASConstraintMaker*make) {

//make.top.left.offset(20);

//针对topLayoutGuide进行设置

// self.mas_bottomLayoutGuide设置底部

// self.mas_topLayoutGuideBottom设置顶部

make.top.equalTo(self.mas_topLayoutGuideBottom);

make.left.offset(20);

make.right.offset(-20);

make.height.equalTo(40);

}];

//设置blueView的约束

/**

dividedBy :除以

multipliedBy :乘以

*/

[blueViewmakeConstraints:^(MASConstraintMaker*make) {

make.top.equalTo(redView.bottom).offset(20);

make.right.offset(-20);

make.height.equalTo(redView);

//宽度

//make.width.equalTo(redView).multipliedBy(0.5);

make.width.equalTo(redView).dividedBy(2);

}];

//更新

[redViewupdateConstraints:^(MASConstraintMaker*make) {

make.height.equalTo(80);

}];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • iOS_autoLayout_Masonry 概述 Masonry是一个轻量级的布局框架与更好的包装AutoLay...
    指尖的跳动阅读 1,303评论 1 4
  • 一、前言 关于苹果的布局一直是我比较纠结的问题,是写代码来控制布局,还是使用storyboard来控制布局呢?以前...
    iplaycodex阅读 2,689评论 0 1
  • (一)Masonry介绍 Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布...
    木易林1阅读 2,558评论 0 3
  • Masonry是一个轻量级的布局框架,拥有自己的描述语法,采用更优雅的链式语法封装自动布局,简洁明了并具有高可读性...
    3dcc6cf93bb5阅读 1,923评论 0 1
  • 女人的魅力在於她的力量與敢於自我表達的勇氣,當她向外坦露自己的堅韌與果敢時,就是她展示自我的時刻。 很多人認為女性...
    好彩妹阅读 102评论 0 0

友情链接更多精彩内容