Masonry布局一

将第三方头文件导入

  // Do any additional setup after loading the view, typically from a nib.
    UIView *greenView = [UIView new];
    greenView.backgroundColor  = [UIColor greenColor];
    greenView.layer.borderWidth = 1;
    greenView.layer.borderColor = [UIColor redColor].CGColor;
    [self.view addSubview:greenView];
    
    UIView *redView = [UIView new];
    redView.backgroundColor = [UIColor redColor];
    redView.layer.borderColor = [UIColor blackColor].CGColor;
    redView.layer.borderWidth =1;
    [self.view addSubview:redView];
    
    UIView *blueView = [UIView new];
    blueView.backgroundColor = [UIColor blueColor];
    blueView.layer.borderWidth = 1;
    blueView.layer.borderColor = [UIColor redColor].CGColor;
    [self.view addSubview:blueView];
    UIView *yellowView = [UIView new];
    yellowView.backgroundColor = [UIColor yellowColor];
    yellowView.layer.borderWidth = 1;
    yellowView.layer.borderColor = [UIColor redColor].CGColor;
    [self.view addSubview:yellowView];
    
    //
    CGFloat padding = 10.0;
    CGFloat topping = 100;
    [greenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topping);
        make.left.mas_equalTo(padding);
        make.right.mas_equalTo(redView.mas_left).offset(-padding);
        make.height.mas_equalTo(100);
        make.width.mas_equalTo(redView);
        
    }];
    
    //
    [redView mas_makeConstraints:^(MASConstraintMaker *make) {
    
        
        make.right.mas_equalTo(yellowView.mas_left).offset(-padding);
        make.left.mas_equalTo(greenView.mas_right).offset(padding);
        make.top.mas_equalTo(topping);
        make.height.mas_equalTo(100);
        make.width.mas_equalTo(greenView);
    }];
    //
    [yellowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(redView.mas_right).offset(padding);
        make.top.mas_equalTo(topping);
        make.right.mas_equalTo(-padding);
        make.height.mas_equalTo(100);
        make.width.mas_equalTo(greenView);
    }];
    //
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(padding);
        make.right.mas_equalTo(-padding);
        make.top.mas_equalTo(greenView.mas_bottom).offset(padding);
        make.height.mas_equalTo(50);
    }];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,034评论 25 709
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,126评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,927评论 19 139
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,480评论 4 61
  • 色泽艳丽,味道鲜美。 每年夏天饭桌上必不可少,唇唇欲动的食物之一:龙虾。 一吃龙虾陷终生。没错,这不是噱头,很多时...
    依食而往阅读 1,351评论 0 0

友情链接更多精彩内容