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);
    }];

你可能感兴趣的:(Masonry布局一)