Masonry的简单使用(一)
Masonry的简单使用(一)
一、新建工程
二、导入Masonry,可从我的GitHub上获取"Masonry":https://github.com/sycFuture/Masonry

三、填入如下代码
- (void)viewDidLoad {
[super viewDidLoad];
UIView *greenView = UIView.new;
greenView.backgroundColor = UIColor.greenColor;
greenView.layer.borderColor = UIColor.grayColor.CGColor;
greenView.layer.borderWidth = 2;
[self.view addSubview:greenView];
UIView *redView = UIView.new;
redView.backgroundColor = UIColor.redColor;
redView.layer.borderColor = UIColor.cyanColor.CGColor;
redView.layer.borderWidth = 2;
[self.view addSubview:redView];
UIView *blueView = UIView.new;
blueView.backgroundColor = UIColor.blueColor;
blueView.layer.borderColor = UIColor.purpleColor.CGColor;
blueView.layer.borderWidth = 2;
[self.view addSubview:blueView];
UIView *orangeView = UIView.new;
orangeView.backgroundColor = UIColor.orangeColor;
orangeView.layer.borderColor = UIColor.brownColor.CGColor;
orangeView.layer.borderWidth = 2;
[self.view addSubview:orangeView];
// 使这三个控件等高
CGFloat padding = 10;//貌似是控件之间的距离
[greenView mas_makeConstraints:^(MASConstraintMaker *make) {
//设置greenView距离顶部的高度和距离左侧的高度均为padding
make.top.left.mas_equalTo(padding);
//设置greenView距离blueView的距离为padding
make.bottom.mas_equalTo(blueView.mas_top).offset(-padding);
//设置左侧距离redView的距离为padding
make.right.mas_equalTo(redView.mas_left).offset(-padding);
//设置greenView与redView等宽
make.width.mas_equalTo(redView);
}];
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.height.mas_equalTo(greenView);
make.left.mas_equalTo(greenView.mas_right).offset(padding);
make.right.mas_equalTo(-padding);
}];
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(greenView.mas_bottom).offset(padding);
make.left.mas_equalTo(padding);
make.right.mas_equalTo(orangeView.mas_left).offset(-padding);
make.bottom.mas_equalTo(-padding);
make.height.mas_equalTo(greenView);
make.width.mas_equalTo(orangeView);
}];
[orangeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.height.bottom.mas_equalTo(blueView);
make.left.mas_equalTo(blueView.mas_right).offset(padding);
make.right.mas_equalTo(-padding);
}];
}
四、运行即可看到如下效果

Masonry的简单使用(一)的更多相关文章
- iOS开发 Masonry的简单使用
首先,在正式使用Masonry之前,我们先来看看在xib中我们是如何使用AutoLayout 从图中我们可以看出,只要设置相应得局限,控制好父视图与子视图之间的关系就应该很ok的拖出你需要的需 ...
- 第三方框架-纯代码布局:Masonry的简单使用
Masonry是一个对系统NSLayoutConstraint进行封装的第三方自动布局框架,采用链式编程的方式提供给开发者API.系统AutoLayout支持的操作,Masonry都支持,相比系统AP ...
- SDAutoLayout:比masonry更简单易用的自动布局库
SDAutoLayout:一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于做最简单易用的AutoLayout库. [SDAutoLa ...
- Masonry的简单使用
#import "RootViewController.h" #import "Masonry.h" @interface RootViewController ...
- Coding源码学习第四部分(Masonry介绍与使用(三))
接上篇继续进行Masonry 的学习. (12)tableViewCell 布局 #import "TableViewController.h" #import "Tes ...
- 自动布局库--Masonry使用
参考资料(戳这里): > Masonry官网 > Masonry介绍与使用实践(快速上手Autolayout) > iOS 开发实践之 Auto Layout > Ma ...
- iOS 资源大全
这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...
- IOS中文版资源库
Swift 语言写成的项目会被标记为 ★ ,AppleWatch 的项目则会被标记为 ▲. [转自]https://github.com/jobbole/awesome-ios-cn#librari ...
- 墙裂推荐 iOS 资源大全
这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...
随机推荐
- 一些centos 6和centos 7的区别
CentOS 6(OLE 6,RHEL 6类似) CcnetOS 7(OLE 7,RHEL 7类似) 影响 默认文件系统 ext4 xfs 大量小文件在ext4上工作性能较好在64位linux中, ...
- [翻译] CotEditor
CotEditor https://github.com/coteditor/CotEditor CotEditor is a lightweight plain-text editor for OS ...
- 转载:从程序员的角度看ASCII, GB2312, UNICODE, UTF-8
以下内容转自博客:http://blog.chinaunix.net/uid-22670933-id-1771613.html. 一.字符编码是怎么回事 0. 概念 字节是计算机的最基本存储单位,一个 ...
- robotFramework--ride 问题:Data source does not exist.
第一次安装robotFramework,运行时提示Data source does not exist.最后发现是在Arguments这一栏误输入了. 导致的,去掉.后就可以正常运行了.
- springsource-tool-suite插件的在线安装
1 首先,确定你现在使用的eclipse属于哪个版本? 查看自己的eclipse平台的版本(我的eclipse平台版本是4.3) 2 根据eclipse版本,选择插件的版本 官网:ht ...
- spring-springmvc-hibernate项目小结
1. web.xml中别忘记加入spring监听器 <listener> <listener-class>org.springframework.web.context.Con ...
- 题解 P1018 【乘积最大】
题目链接:P1018 乘积最大 题面 今年是国际数学联盟确定的"2000――世界数学年",又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面 ...
- #001 GIT创建分支
GitHub创建分支 如何在github 创建 一个分支出来,进行开发,最后在 merge 到主干上. Git 操作命令 git branch branchName //创建一个分支 git chec ...
- 关于markdown格式的测试..
标题 标题一 这是? 标题二 标题三 标题四 区块 1.这是一个列表项目 还是吗? 嵌套了? 空格了? 区块加列表 标题加二级列表 嘿嘿 无序列表 RED GREEN BLUE 有序列表 dog ca ...
- html5小结
本文提到的HTML5仅仅指于2014年完成新一代的HTML标准. html5主要在以下方面做了改变. 1.新增标签 新增语义化标签. <header> 定义 section 或 page ...