#import "RootViewController.h"
#import "Masonry.h"
@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
#pragma mark label
    // 添加约束,不需要这只frame
    UILabel *label = [UILabel new];
    label.backgroundColor = [UIColor redColor];
    // 添加父视图,视图添加完成之后才能进行布局
    [self.view addSubview:label];

    // 布局,实现布局方法
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        // 距离上面50
        // make:相当于你要布局的视图,equalTo(参照视图的对象),如果参照视图是self.view,可以不设置参照视图的属性(就是top)
        make.top.offset();

        // 距离左边100;
        make.left.offset();

        // 距离右边100

        make.right.equalTo(self.view).offset(-);

        // 距离下面500
        make.bottom.equalTo(self.view).offset(-);

    }];

#pragma mark label1

    UILabel *label1 = [UILabel new];
    label1.backgroundColor = [UIColor greenColor];
    [self.view addSubview:label1];

    // 布局label1
   //  先布局参照视图,否则约束容易丢失
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        //和label左边一致
        // equalTo(自定义视图),需要设置视图的属性
        // 如果是数值为0可以不写offset()
        make.leading.equalTo(label.mas_leading);
        //和label右边一致
        make.trailing.equalTo(label.mas_trailing);
        //上边距离label50
        make.top.equalTo(label.mas_bottom).offset();
        // 高度60
        // mas_equalTo(数值)
        make.height.mas_equalTo();
    }];

#pragma mark label2

    UILabel *label2 = [UILabel new];
    label2.backgroundColor = [UIColor cyanColor];
    [self.view addSubview:label2];
    // 设置距离参照视图的内边距(上左下右)
    UIEdgeInsets padding = UIEdgeInsetsMake(, , , );

    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view).offset(400);
//        make.left.equalTo(self.view).offset(100);
//        make.right.equalTo(self.view).offset(-100);
//        make.bottom.equalTo(self.view).offset(-100);
        // 设置约束视图的边界距离self.view边界值
        make.edges.equalTo(self.view).insets(padding);
    }];

#pragma mark label3

    UILabel *label3 = [UILabel new];
    label3.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:label3];

    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {

        // 设置中心点一致
        make.center.equalTo(label2);

        // 设置大小

        // make.width = label2.width - 40
        // make.height = label2.height - 60
        make.size.equalTo(label2).sizeOffset(CGSizeMake(-, -));

    }];

}

Masonry的简单使用的更多相关文章

  1. Masonry的简单使用(一)

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

  2. iOS开发 Masonry的简单使用

    首先,在正式使用Masonry之前,我们先来看看在xib中我们是如何使用AutoLayout     从图中我们可以看出,只要设置相应得局限,控制好父视图与子视图之间的关系就应该很ok的拖出你需要的需 ...

  3. 第三方框架-纯代码布局:Masonry的简单使用

    Masonry是一个对系统NSLayoutConstraint进行封装的第三方自动布局框架,采用链式编程的方式提供给开发者API.系统AutoLayout支持的操作,Masonry都支持,相比系统AP ...

  4. SDAutoLayout:比masonry更简单易用的自动布局库

    SDAutoLayout:一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于做最简单易用的AutoLayout库. [SDAutoLa ...

  5. Coding源码学习第四部分(Masonry介绍与使用(三))

    接上篇继续进行Masonry 的学习. (12)tableViewCell 布局 #import "TableViewController.h" #import "Tes ...

  6. 自动布局库--Masonry使用

    参考资料(戳这里): >  Masonry官网 >  Masonry介绍与使用实践(快速上手Autolayout) >  iOS 开发实践之 Auto Layout >  Ma ...

  7. iOS 资源大全

    这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...

  8. IOS中文版资源库

    Swift 语言写成的项目会被标记为  ★ ,AppleWatch 的项目则会被标记为 ▲. [转自]https://github.com/jobbole/awesome-ios-cn#librari ...

  9. 墙裂推荐 iOS 资源大全

    这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...

随机推荐

  1. Bash shell 的算术运算有四种方式

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1:使用 expr 外部程式加法 r=`expr 4 + 5`echo $r注意! '4' '+' '5' 这三者之间要有空白r=`e ...

  2. apache、nginx、iis 全球分布

    从下图(2012年8月份的数据)来看,来自俄罗斯的Nginx服务器,主要使用区域也集中在俄罗斯及周边国家.微软的IIS,在中国使用最多,占其总份额的57.6%,其他国家如埃及.沙特阿拉伯等国家也基本使 ...

  3. (中等) POJ 2991 Crane , 几何+线段树。

    Description ACM has bought a new crane (crane -- jeřáb) . The crane consists of n segments of variou ...

  4. 利用智能手机(Android)追踪一块磁铁(转)

    利用智能手机(Android)追踪一块磁铁(一) 利用智能手机(Android)追踪一块磁铁(二) 利用智能手机(Android)追踪一块磁铁(三)

  5. salt自动化部署

    1. 到编译机器编译 /export/Deploy/vm-agent 执行脚本 ./vm-agent.sh develop -alpha 2.检查rpm包是否打包成功 http://172.18.13 ...

  6. STM32的时钟树深入详解以及RCC配置

    在STM32上如果不使用外部晶振,OSC_IN和OSC_OUT的接法 如果使用内部RC振荡器而不使用外部晶振,请按照下面方法处理: 1)对于100脚或144脚的产品,OSC_IN应接地,OSC_OUT ...

  7. 前端轻量级web进度条 – Nprogress & nanobar

    转载:http://www.xuanfengge.com/front-end-nprogress-and-lightweight-web-progress-bar-nanobar.html 前言 进度 ...

  8. java 正则匹配int型

    private static Pattern DIGIT_PATTERN = Pattern.compile("=\\d++"); Matcher goodsTypeMatcher ...

  9. iOS MVVM 前世今生

    MVVM,Model-View-ViewModel,一个从 MVC 模式中进化而来的设计模式,最早于2005年被微软的 WPF 和 Silverlight 的架构师 John Gossman 提出.

  10. Spring Boot Web Executable Demo

    Spring Boot Web Executable Demo */--> pre.src {background-color: #292b2e; color: #b2b2b2;} pre.sr ...