Masory框架

来源:互联网 发布:室内设计需要哪些软件 编辑:程序博客网 时间:2024/06/05 03:20

Masory介绍:

1.默认情况下:
mas_equalTo有自动包装功能,比如自动将20包装为@20
equalTo没有自动包装功能

2.如果添加了下面的宏,那么mas_equalTo和equalTo就没有区别,注意:这个宏一定要添加到#import "Masonry.h"前面

#define MAS_SHORTHAND_GLOBALS

3.默认情况下:

  • width是make对象的一个属性,用来添加宽度约束用的,表示对宽度进行约束
  • mas_width是一个属性值,用来当做equalTo的参数,表示某个控件的宽度属性
  • 如果添加了下面的宏,mas_width也可以写成width
    #define MAS_SHORTHAND
    mas_height、mas_centerX以此类推

4.示范代码:

#import "ViewController.h"//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"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // 1.创建蓝色的view添加到控制器中    UIView *blueView = [[UIView alloc] init];    blueView.backgroundColor = [UIColor blueColor];    [self.view addSubview:blueView];    // 2.创建红色的view添加到控制器中    UIView *redView = [[UIView alloc] init];    redView.backgroundColor = [UIColor redColor];    [self.view addSubview:redView];    // 3.添加新的约束    [blueView makeConstraints:^(MASConstraintMaker *make) {        make.left.equalTo(self.view.left).offset(30);        make.bottom.equalTo(self.view.bottom).offset(-30);        make.right.equalTo(redView.left).offset(-30);        make.width.equalTo(redView.width);//        make.height.equalTo(50);    }];    [redView makeConstraints:^(MASConstraintMaker *make) {        make.right.equalTo(self.view.right).offset(-30);        make.top.equalTo(blueView.top);        make.bottom.equalTo(blueView.bottom);    }];    // 4.更新约束    [blueView updateConstraints:^(MASConstraintMaker *make) {        make.height.equalTo(80);    }];    // 5.删除之前所有的约束,重新添加约束//    [blueView remakeConstraints:^(MASConstraintMaker *make) {//        //    }];

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

- (MASConstraint *)with {              return self;}- (MASConstraint *)and {              return self;}
0 0
原创粉丝点击