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 ...
随机推荐
- idea常用到的命令
idea大小写转换:ctr+shift+u ctrl+alt+b,跳转到接口的方法实现处
- 转:MVC框架
MVC框架是什么 MVC (Modal View Controler)本来是存在于Desktop程序中的,M是指数据模型,V是指用户界面,C则是控制器.使用MVC的目的是将M和V的实现代码分离,从而使 ...
- 转:未能打开编辑器:Unmatched braces in the pattern.
原文地址:http://blog.csdn.net/hytdsky/article/details/4736462 Eclipse出现这个问题而不能查看源代码 原因就是语言包的问题 出现这个问题了 ...
- 精简计算UITableView文本高度
精简计算UITableView文本高度 本人视频教程系类 iOS中CALayer的使用 最终效果: 核心源码(计算文本高度的类) NSString+StringHeight.h 与 NSStrin ...
- [翻译] ZFDragableModalTransition
ZFDragableModalTransition Usage - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender ...
- esxcli software vib 命令为 ESXi 5.x/6.x 主机安装补丁程序 (2008939)
参考KB:https://kb.vmware.com/s/article/2008939?lang=zh_CN Symptoms 免责声明:本文为 “esxcli software vib” ...
- matlab操作(整理)
http://blog.csdn.net/ysuncn/article/details/1741828 http://zhan.renren.com/h5/entry/3602888498000464 ...
- September 07th 2017 Week 36th Thursday
With the most true of yourself, can you meet the most suitable one. 用最真实的自己,才能遇见最合适的那个人. You are alw ...
- CSS 构造表格
表格边框 CSS 中设置表格边框,请使用 border 属性: <style type="text/css"> table{ border:1px solid red; ...
- 1070. [SCOI2007]修车【费用流】
Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同 的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序, ...