您的位置:首页 > 移动开发 > IOS开发

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

2015-07-01 10:19 495 查看
#import "ThreeViewController.h"

#import "View+MASAdditions.h"

#import "UIView+Masonry_LR.h"

#import "FourViewController.h"

static NSString const*kStoryboardName=@"ThreeViewController";

static NSString const*kIdentifier=@"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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: