您的位置:首页 > 编程语言

代码:Masonry 第三方框架

2015-12-03 08:36 204 查看
必备宏使用前提:

//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND
//define this constant if you want to enable auto-boxing for default syntax

#define MAS_SHORTHAND_GLOBALS
#import "Masonry.h"

代码实现 :
// 蓝色控件
UIView *blueView = [[UIView alloc] init];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];

// 红色控件
UIView *redView = [[UIView alloc] init];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];

// 添加约束
CGFloat margin = 20;//这是抽取的值,下面我用实例说明:可以直接使用数字
CGFloat height = 50;
//添加蓝色的约束:只要用蓝色视图调用这个方法,下面就不需要写blueView
[blueView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.left).offset(20);//视图的左边等于父视图的左边并修正多少
make.right.equalTo(redView.left).offset(-20);//视图的右边边等于红色视图的右边并修正多少
make.bottom.equalTo(self.view.bottom).offset(-margin);
make.height.equalTo(height);//视图高度等于一个固定高度
make.top.equalTo(redView.top);// 视图的上面和红色视图的上面相等
make.bottom.equalTo(redView.bottom);// 视图的下面和红色视图的下面相等
make.width.equalTo(redView.width);// 视图的宽度和红色视图的宽度相等
}];
//添加红色视图的约束
[redView makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view.right).offset(-margin);

}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: