天天看点

iOS masonry设置六个等高等宽的view

#import "ThreeViewController.h"

#import "View+MASAdditions.h"

#import "UIView+Masonry_LR.h"

#import "FourViewController.h"

static NSString const*[email protected]"ThreeViewController";

static NSString const*[email protected]"ThreeViewController";

#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;

@interface ThreeViewController ()

@end

@implementation ThreeViewController

+ (instancetype)createViewControllerWithStoryboard:(id)createArgs{

    UIStoryboard *storyboard=[UIStoryboard storyboardWithName:(NSString *)kStoryboardName bundle:nil];

    ThreeViewController *vc=[storyboard instantiateViewControllerWithIdentifier:(NSString *)kIdentifier];

    return vc;

}

- (void)viewDidLoad {

    [super viewDidLoad];

    [self setTitle:@"第三个约束"];

    [self initView];

    [self initRight];

}

- (void)initRight{

    UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithTitle:@"第四个约束" style:UIBarButtonItemStylePlain target:self action:@selector(right)];

    self.navigationItem.rightBarButtonItem=right;

}

- (void)right{

    FourViewController *vc=[FourViewController createViewControllerWithStoryboard:nil];

    [self.navigationController pushViewController:vc animated:YES];

}

- (void)initView{

    WS(ws);

    UIView *view=[UIView new];

    view.backgroundColor=[UIColor brownColor];

    [self.view addSubview:view];

    [view mas_makeConstraints:^(MASConstraintMaker *make) {

        make.center.equalTo(ws.view);

        make.size.mas_equalTo(CGSizeMake(300, 300));

    }];

    UIView *view1 = [UIView new];

    UIView *view2 = [UIView new];

    UIView *view3 = [UIView new];

    UIView *view4 = [UIView new];

    UIView *view5 = [UIView new];

    UIView *view6 = [UIView new];

    view1.backgroundColor = [UIColor redColor];

    view2.backgroundColor = [UIColor blueColor];

    view3.backgroundColor = [UIColor cyanColor];

    view4.backgroundColor = [UIColor yellowColor];

    view5.backgroundColor = [UIColor blackColor];

    view6.backgroundColor = [UIColor lightGrayColor];

    [view addSubview:view1];

    [view addSubview:view2];

    [view addSubview:view3];

    [view addSubview:view4];

    [view addSubview:view5];

    [view addSubview:view6];

    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(@[view2]);

        make.centerX.equalTo(@[view3,view5]);

        make.size.mas_equalTo(CGSizeMake(80, 80));

    }];

    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(@[view1]);

        make.centerX.equalTo(@[view4,view6]);

        make.size.mas_equalTo(CGSizeMake(80, 80));

    }];

    [view3 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(@[view4]);

        make.size.mas_equalTo(CGSizeMake(80, 80));

    }];

    [view4 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(@[view3]);

        make.size.mas_equalTo(CGSizeMake(80, 80));

    }];

    [view5 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(@[view6]);

        make.size.mas_equalTo(CGSizeMake(80, 80));

    }];

    [view6 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.size.mas_equalTo(CGSizeMake(80, 80));

    }];

    [view distributeSpacingHorizontallyWith:@[view1,view2]];

    [view distributeSpacingVerticallyWith:@[view1,view3,view5]];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}

iOS masonry设置六个等高等宽的view