//
// ViewController.m
// 03-masonry的基本使用
//
// Created by on 16/5/5.
// Copyright (c) 2016年 鹿微微鹿. All rights reserved.
//
结果的截图
#import "ViewController.h"
#import "Masonry.h"
ViewController ()
@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);
}];
}