美文网首页
10.1 Masonry简单介绍

10.1 Masonry简单介绍

作者: 草根小强 | 来源:发表于2019-04-25 17:15 被阅读0次
    #import "ViewController.h"
    #import "Masonry.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
       
        UIView *blueView = [[UIView alloc]init];
        blueView.backgroundColor = UIColor.blueColor;
        [self.view addSubview:blueView];
        
        UIView *greenView = [[UIView alloc]init];
        greenView.backgroundColor = UIColor.greenColor;
        [self.view addSubview:greenView];
        
        //mas_makeConstraints 添加约束
        [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
            //trailing 右侧  equalTo相对于哪个视图 offset 约束值
            make.trailing.equalTo(self.view).offset(-50);
            //equalTo() 参数必须是对象 如果约束相对于父视图的话 可以使用下面的写法
            make.bottom.equalTo(@(-50));
            
            make.width.equalTo(@100);
            //mas_equalTo()参数可以使基础类型
            make.height.mas_equalTo(60);
        }];
        
        [greenView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(blueView.mas_leading).offset(-60);
            make.bottom.mas_equalTo(blueView.mas_top).offset(-60);
            make.width.mas_equalTo(blueView);
            make.height.mas_equalTo(60);
        }];
        
        //删除旧约束 跟新新约束
    //    [greenView mas_remakeConstraints:^(MASConstraintMaker *make) {
    //        
    //    }];
        
        //更新约束
    //    [greenView mas_updateConstraints:^(MASConstraintMaker *make) {
    //        
    //    }];
        
    }
    @end
    
    
    Masonry简单介绍.png

    相关文章

      网友评论

          本文标题:10.1 Masonry简单介绍

          本文链接:https://www.haomeiwen.com/subject/rcgzgqtx.html