IOS開發之masonry的基本使用

//spa

//  ViewController.m.net

//  03-masonry的基本使用3d

//orm

//  Created by on 16/5/5.get

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

//io

結果的截圖class



#import "ViewController.h"import

#import "Masonry.h"im

@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

相關文章
相關標籤/搜索