Masonry的使用1
2016-01-29 21:51
405 查看
#import "ViewController.h" #import "Masonry.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 1.创建控件 UIView *blueView = [[UIView alloc] init]; blueView.backgroundColor = [UIColor blueColor]; [self.view addSubview:blueView]; // 2.添加约束 //尺寸:100x100 //位置:父控件右下角,间距20 [blueView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.equalTo(@100); make.right.equalTo(self.view.mas_right).offset(-20); make.bottom.equalTo(self.view.mas_bottom).offset(-20); }]; } /* //这个方法会将以前的所有约束删掉,添加新的约束 [blueView mas_remakeConstraints:^(MASConstraintMaker *make) { }]; //这个方法将会覆盖以前的某些约束 [blueView mas_updateConstraints:^(MASConstraintMaker *make) { }]; */ @end代码优化:
[blueView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(100); make.right.bottom.equalTo(self.view).offset(-20); }];继续优化:
[blueView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(100, 100)); make.right.bottom.mas_equalTo(self.view).offset(-20); }];
相关文章推荐
- Intent 传值和 Bundle传值的区别
- OpenAL alDistanceModel函数使用详解
- 屏蔽上网时弹窗广告,防止追踪、恶意域名,过滤横幅广告、以及视频广告的方法
- Splinter学习--初探1,模拟百度搜索
- code vs 1966 乘法游戏
- 【codevs1962】马棚问题
- 2016蓝桥杯基础训练——特殊回文数
- 利用NTFS交换数据流隐藏文件
- 谁也无法挡住我访问Google---使用Nginx反向代理攻略
- 将DLL和EXE打包成一个EXE
- Android--viewpager学习
- Log4j 2.0在开发中的高级使用具体解释—配置简单的控制台输出(三)
- 隐写术总结
- 20160129
- python class中的@staticmethod
- Hadoop笔记
- 前端笔记---随手记
- Virtual-Key Codes 微软官方
- 黑马程序员——Java泛型
- Spring MVC+Hibernate+Spring框架整合