IOS开发之masonry的基本使用

//

//  ViewController.m

//  03-masonry的基本使用

//

//  Created by on 16/5/5.

//  Copyright (c) 2016 鹿微微鹿. All rights reserved.

//

结果的截图



#import "ViewController.h"

#import "Masonry.h"

@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

   

    //1.将需要约束的视图全部添加显示

    UIView *greenView = [[UIView alloc]init];

    greenView.backgroundColor = [UIColor greenColor];

    

    UIView *redView = [[UIView alloc]init];

    redView.backgroundColor = [UIColor redColor];

    

    UIView *purpleView = [[UIView alloc]init];

    purpleView.backgroundColor = [UIColor purpleColor];

    

    [self.view addSubview:redView];

    [self.view addSubview:greenView];

    [self.view addSubview:purpleView];

    

    //2.添加约束

    CGFloat margin = 20;

    //绿色视图

    [greenView mas_makeConstraints:^(MASConstraintMaker *make) {

       //make代表当前这个视图

        //给视图添加约束的时候就添加到make

        make.left.equalTo (self.view.mas_left).offset(margin);

        make.top.equalTo(self.view.mas_top).offset(margin);

        make.right.equalTo(redView.mas_left).offset(-margin);

        make.bottom.equalTo(purpleView.mas_top).offset(-margin);

        make.width.equalTo(redView.mas_width);

        make.height.equalTo(redView.mas_height);

        make.height.equalTo(purpleView.mas_height);

    }];

    

    //红色视图

    [redView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo (redView.mas_right).offset(margin);

        make.top.equalTo(self.view.mas_top).offset(margin);

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

        make.bottom.equalTo(purpleView.mas_top).offset(-margin);

        make.width.equalTo(greenView.mas_width);

        make.height.equalTo(greenView.mas_height);

        make.height.equalTo(purpleView.mas_height);

    }];

    

    

    //紫色视图

    [purpleView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo (self.view.mas_left).offset(margin);

        make.top.equalTo(redView.mas_bottom).offset(margin);

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

        make.bottom.equalTo(self.view.mas_bottom).offset(-margin);

        make.height.equalTo(greenView.mas_height);

    }];

    

}




@end



















转载于:https://my.oschina.net/luhoney/blog/670509

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值