#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. mysql、mysqli、pdo使用

    一.php手册关于MySQL的说明:    This extension is not recommended for writing new code. Instead, either themys ...

  2. (中等) HDU 4725 The Shortest Path in Nya Graph,Dijkstra+加点。

    Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...

  3. 关于JAVA中hashCode

    hash code 即散列码根据对象计算出的一个整型值,散列码是没有规律的. 如果两个对象相等(equal() 返回true),则hashCode一定相等,如果两个对象hashCode相等,则对象不一 ...

  4. Mybatis 模糊查询 中文问题

    IDE编码:GBK ,换成UTF-8也不行! @Testpublic void testSearchStudents() {logger.info("查询学生(带条件)");Map ...

  5. 开启分布式事物DTC

    1.web服务器开启分布式事物配置后,数据库服务器的host文件要设置  “IP  web服务器主机名” 的映射,否则会 出现 “与基础事务管理器的通信失败” #跨网段使用TransactionSco ...

  6. DOMContentLoaded

    setTimeout(function(){ alert("settimeout"); },0); EventUtil.addHandler(window, "DOMCo ...

  7. iOS 之 导航栏按钮

    UIButton *releaseButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [releaseButton setTitle ...

  8. Angular - - angular.bind、angular.bootstrap、angular.copy

    angular.bind 返回一个调用self的函数fn(self代表fn里的this).可以给fn提供参数args(*).这个功能也被称为局部操作,以区别功能. 格式:angular.bind(se ...

  9. js架构设计模式——前端MVVM框架设计及实现(一)

    前端MVVM框架设计及实现(一) 最近抽出点时间想弄个dom模块化的模板引擎,不过现在这种都是MVVM自带的,索性就想自己造轮子写一个简单的MVVM框架了 借鉴的自然还是从正美的avalon开始了,我 ...

  10. Linux释放内存脚本

    vi recover_mem.sh #!/bin/bash  ################## #author:rrhelei@126.com# ################## #系统分配的 ...