Masonry 布局 基本操作 小结

本文介绍Masonry库在iOS开发中的应用,重点讲解了mas_makeConstraints、mas_updateConstraints与mas_remakeConstraints三个方法的区别与使用场景,并提供了全屏布局的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

呐,Masonry 是用来布局的!CocoaPods上下载!

呐,来吧!开始鸟语......下面是从View+MASAdditions.h中抽出来的方法。

 

 1 /**
 2  *  Creates a MASConstraintMaker with the callee view.
 3  *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing
 4  *
 5  *  @param block scope within which you can build up the constraints which you wish to apply to the view.
 6  *
 7  *  @return Array of created MASConstraints
 8  */
 9 - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
10 
11 /**
12  *  Creates a MASConstraintMaker with the callee view.
13  *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
14  *  If an existing constraint exists then it will be updated instead.
15  *
16  *  @param block scope within which you can build up the constraints which you wish to apply to the view.
17  *
18  *  @return Array of created/updated MASConstraints
19  */
20 - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
21 
22 /**
23  *  Creates a MASConstraintMaker with the callee view.
24  *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
25  *  All constraints previously installed for the view will be removed.
26  *
27  *  @param block scope within which you can build up the constraints which you wish to apply to the view.
28  *
29  *  @return Array of created/updated MASConstraints
30  */
31 - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;

土鳖式翻译开始...  对比:

mas_makeConstraints     created
mas_updateConstraints   created/updated   If an existing constraint exists then it will be updated instead.
                          (如果现有的约束存在,那么它将被更新。)
mas_remakeConstraints    created/updated  All constraints previously installed for the view will be removed.
                          (视图上之前安装的所有约束将被删除。人家的意思是会保留最新哒) 

 

简单使用方法:

人家想来个全屏的么,除了导航栏。

1  [myView mas_makeConstraints:^(MASConstraintMaker *make) {
2         make.top.equalTo(self.view.mas_top).with.offset(64);//
3         make.left.equalTo(self.view.mas_left);    //
4         make.right.equalTo(self.view.mas_right);//
5         make.bottom.equalTo(self.view.mas_bottom);//
6     }];

 

其他方法自行脑补~揍四Autolayout。

下面贴个详细的帖子,I like   ~~~  http://adad184.com/2014/09/28/use-masonry-to-quick-solve-autolayout/

 
 

 

转载于:https://www.cnblogs.com/hanyutong/p/4770998.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值