框架地址:
Masory介紹:
1.默認(rèn)情況下:
mas_equalTo有自動包裝功能柿冲,比如自動將20包裝為@20
equalTo沒有自動包裝功能
2.如果添加了下面的宏嚼黔,那么mas_equalTo和equalTo就沒有區(qū)別,注意:這個宏一定要添加到#import "Masonry.h"前面
#define MAS_SHORTHAND_GLOBALS
3.默認(rèn)情況下:
- width是make對象的一個屬性辜限,用來添加寬度約束用的蝙昙,表示對寬度進(jìn)行約束
- mas_width是一個屬性值厂僧,用來當(dāng)做equalTo的參數(shù)堤如,表示某個控件的寬度屬性
- 如果添加了下面的宏谎僻,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.創(chuàng)建藍(lán)色的view添加到控制器中
UIView *blueView = [[UIView alloc] init];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];
// 2.創(chuàng)建紅色的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;
}
- Posted by *** singerYoung ***
- 聯(lián)系作者 簡書·singerYoung 新浪微博·小小羊run
- 原創(chuàng)文章粮坞,版權(quán)聲明:自由轉(zhuǎn)載-非商用-非衍生-保持署名