您的位置:首页 > 其它

Masonry的使用1

2016-01-29 21:51 405 查看

#import "ViewController.h"
#import "Masonry.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

// 1.创建控件
UIView *blueView = [[UIView alloc] init];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];

// 2.添加约束
//尺寸:100x100
//位置:父控件右下角,间距20
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@100);
make.right.equalTo(self.view.mas_right).offset(-20);
make.bottom.equalTo(self.view.mas_bottom).offset(-20);
}];

}

/*
//这个方法会将以前的所有约束删掉,添加新的约束
[blueView mas_remakeConstraints:^(MASConstraintMaker *make) {

}];

//这个方法将会覆盖以前的某些约束
[blueView mas_updateConstraints:^(MASConstraintMaker *make) {

}];
*/
@end
代码优化:
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(100);
make.right.bottom.equalTo(self.view).offset(-20);
}];
继续优化:
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(100, 100));
make.right.bottom.mas_equalTo(self.view).offset(-20);
}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: