你的位置:首页 > 软件开发 > 操作系统 > 【原】iOS学习之Masonry第三方约束

【原】iOS学习之Masonry第三方约束

发布时间:2016-08-31 20:00:05
1、Masonry概述目前最流行的Autolayout第三方框架  用优雅的代码方式编写Autolayout  省去了苹果官方恶心的Autolayout代码  大大提高了开发效率 框架地址:https://github.com/SnapKit/Masonry2、常用方法这个方 ...

1、Masonry概述

  • 目前最流行的Autolayout第三方框架

  用优雅的代码方式编写Autolayout

  省去了苹果官方恶心的Autolayout代码

  大大提高了开发效率

  •  框架地址:https://github.com/SnapKit/Masonry

2、常用方法

  • 这个方法只会添加新的约束
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {}];

  如果添加了下面的宏,mas_width也可以写成width

  #define MAS_SHORTHAND

//define this constant if you want to use Masonry without the 'mas_' prefix#define MAS_SHORTHAND//define this constant if you want to enable auto-boxing for default syntax#define MAS_SHORTHAND_GLOBALS#import "Masonry.h" - (void)viewDidLoad {  [super viewDidLoad];    // 蓝色控件  UIView *blueView = [[UIView alloc] init];  blueView.backgroundColor = [UIColor blueColor];  [self.view addSubview:blueView];    // 红色控件  UIView *redView = [[UIView alloc] init];  redView.backgroundColor = [UIColor redColor];  [self.view addSubview:redView];    // 添加约束  CGFloat margin = 20;  CGFloat height = 50;  [blueView makeConstraints:^(MASConstraintMaker *make) {    make.left.equalTo(self.view.left).offset(margin);    make.right.equalTo(redView.left).offset(-margin);    make.bottom.equalTo(self.view.bottom).offset(-margin);    make.height.equalTo(height);    make.top.equalTo(redView.top);    make.bottom.equalTo(redView.bottom);    make.width.equalTo(redView.width);  }];    [redView makeConstraints:^(MASConstraintMaker *make) {    make.right.equalTo(self.view.right).offset(-margin);  }];} 

5、可有可无的用法

  以下方法都仅仅是为了提高可读性,可有可无

  • with
- (MASConstraint*)with {  return self;}   

原标题:【原】iOS学习之Masonry第三方约束

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。