您的位置:首页 > 其它

Masory框架

2016-07-08 23:22 225 查看

Masory介绍:

1.默认情况下:mas_equalTo有自动包装功能,比如自动将20包装为@20equalTo没有自动包装功能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;
}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Masory 框架