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];
}
#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];
}
相关文章推荐
- iOS masonry动态约束控件位置
- iOS Crash收集框架
- cisco 交换机恢复IOS与更改波特率
- 使用Xcode和Instruments调试解决iOS内存泄露
- ios支付宝支付开发
- iOS项目添加CocoaPods
- IOS上如何画出1像素的线
- AFNetWorking在IOS9 请求数据失败解决方案
- IOS字符转义 URL encode 的方法
- iOS开发之多表视图滑动切换示例(仿"头条"客户端)
- iOS开发之Relaese时关闭NSLog使之不在控制台显示
- 开始iOS 7中自动布局教程
- [Mac] Mac OS/iOS/XCode版本历史
- iOS 真机调试(最具体的步骤来解决历史,hmt精心打造)
- ZZCustomAlertView - 一个高度自定义的iOS模态弹窗
- ZZCustomAlertView - 一个高度自定义的iOS模态弹窗
- iOS蓝牙编程
- 获取iOS设备信息
- 使用plist固化iOS应用数据
- IOS RUNTIME笔记