Massary屏幕适配,自动布局
2016-06-26 00:00
375 查看
摘要: 开发往往需要适配多种屏幕,一种屏幕写一套布局太过于麻烦,所以用Massary来根据不同屏幕自动布局,简化开发,提高效率。
- (void)viewDidLoad { [super viewDidLoad]; // 添加红蓝两个控件 UIView *blueView = [[UIView alloc]init]; blueView.backgroundColor = [UIColor blueColor]; blueView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:blueView]; UIView *redView = [[UIView alloc]init]; redView.backgroundColor = [UIColor redColor]; redView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:redView]; // 添加约束 /** 练习1: */ /* [blueView mas_makeConstraints:^(MASConstraintMaker *make) { // 固定大小用mas_equalTo make.width.mas_equalTo(100); make.height.mas_equalTo(100); // 与其他控件比较equalTo make.centerX.equalTo(self.view.mas_centerX); make.centerY.equalTo(self.view.mas_centerY); }]; */ /** 练习2: */ /* [blueView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.mas_left).offset(30); make.bottom.equalTo(self.view.mas_bottom).offset(-30); make.right.equalTo(redView.mas_left).offset(-30); make.height.mas_equalTo(50); }]; [redView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.view.mas_right).offset(-30); make.bottom.equalTo(blueView.mas_bottom); make.height.equalTo(blueView.mas_height); make.width.equalTo(blueView.mas_width); }]; */ /** 练习3: */ /* [blueView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.mas_left).offset(30); make.top.equalTo(self.view.mas_top).offset(30); make.right.equalTo(self.view.mas_right).offset(-30); make.height.mas_equalTo(50); }]; [redView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(blueView.mas_right); make.top.equalTo(blueView.mas_bottom).offset(30); make.height.equalTo(blueView.mas_height); make.left.equalTo(blueView.mas_centerX); }]; */ // 删除约束,重新添加 [blueView mas_remakeConstraints:^(MASConstraintMaker *make) { }]; // 更新约束 [blueView mas_updateConstraints:^(MASConstraintMaker *make) { }]; }
//方法一,array 的 mas_distributeViewsAlongAxis /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fixedSpacing 间隔大小 * @param leadSpacing 头部间隔 * @param tailSpacing 尾部间隔 */ // MASAxisTypeHorizontal 水平 // MASAxisTypeVertical 垂直 [arrayList mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:20 leadSpacing:5 tailSpacing:5]; [arrayList mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(60); make.height.mas_equalTo(100); }]; /** * 多个固定大小的控件的等间隔排列,变化的是间隔的空隙 * * @param axisType 轴线方向 * @param fixedItemLength 每个控件的固定长度或者宽度值 * @param leadSpacing 头部间隔 * @param tailSpacing 尾部间隔 */ [arrayList mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedItemLength:60 leadSpacing:40 tailSpacing:10]; [arrayList mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.mas_equalTo(100); // make.height.mas_equalTo(100); make.left.mas_equalTo(20); make.right.mas_equalTo(-20); }];
相关文章推荐
- Android-屏幕适配需要注意的地方总结
- iOS应用中使用Auto Layout实现自定义cell及拖动回弹
- iOS应用开发中使用Auto Layout来适配不同屏幕尺寸
- Swift: 你好, AutoLayout!
- Android dpi,dip,dp的概念以及屏幕适配
- ios8新特性屏幕适配之sizeclass
- IOS自动布局与非自动布局嵌套使用的解决办法
- iOS屏幕旋转学习笔记
- iOS屏幕适配
- AutoLayout-VFL代码布局<一>
- AutoLayout-代码布局添加动画
- iOS autoresizingMask与autoLayout
- autolayout 设置使用tableviewHeaderView
- iOS布局和屏幕适配
- iOS 代码 AutoLayout
- AutoLayout布局 知识点
- IOSAutoLayout详解
- iOSAutoLayout自动布局中级开发教程(5)修改约束的值 延迟加载
- 分享一个 ios 自动适配的资料