记录一下,Masonry的简单使用
UIView *spView = [[UIView alloc] init];
spView.backgroundColor = [UIColor grayColor];
[self.view addSubview:spView];
UIView *blue = [UIView new];
blue.backgroundColor = [UIColor blueColor];
[spView addSubview:blue];
self.blue = blue;
UIView *red = [UIView new];
red.backgroundColor = [UIColor redColor];
[spView addSubview:red];
self.red = red;
[spView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view).with.mas_offset(UIEdgeInsetsMake(80, 50, 60, 50));
}];
/*
UILabel *titleLab = [UILabel new];
titleLab.text = @"第一种情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况情况 ";
titleLab.backgroundColor = [UIColor greenColor];
titleLab.numberOfLines = 0;
[spView addSubview:titleLab];
[titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.mas_equalTo(spView).mas_offset(UIEdgeInsetsMake(10, 10, 0, 10));
}];
*/
/*
方式 1 上下排列
[blue mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.and.top.mas_equalTo(spView).mas_offset(UIEdgeInsetsMake(10, 10, 0, 10));
make.height.mas_equalTo(100);
}];
[red mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.mas_equalTo(spView).mas_offset(UIEdgeInsetsMake(0, 10, 0, 10));
make.top.mas_equalTo(blue.mas_bottom).mas_offset(10);
make.height.mas_equalTo(blue.mas_height).multipliedBy(0.5);
}];
*/
/*
//方式 2 左右等宽高排列
[blue mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(spView).mas_offset(10);
make.right.mas_equalTo(red.mas_left).mas_offset(-10);
make.height.mas_equalTo(100);
make.centerY.mas_equalTo(spView);
make.width.mas_equalTo(red);
make.height.mas_equalTo(red);
}];
[red mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(blue.mas_right);
make.right.mas_equalTo(spView).mas_offset(-10);
make.centerY.mas_equalTo(spView);
}];
*/
/*
//方式 3 左右排列 左固定宽 右边不定宽
[blue mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(spView).mas_offset(10);
make.right.mas_equalTo(red.mas_left).mas_offset(-10);
make.size.mas_equalTo(CGSizeMake(100, 100));
make.centerY.mas_equalTo(spView);
make.height.mas_equalTo(red);
}];
[red mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(spView);
make.right.mas_equalTo(spView).mas_offset(-10);
make.left.mas_equalTo(blue.mas_right);
}];
*/
/*
//方式 4 左右排列 右固定宽 左边不定宽
[red mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(50, 100));
make.top.mas_equalTo(spView).mas_offset(50);
make.right.mas_equalTo(spView).mas_offset(-10);
make.height.mas_equalTo(blue);
}];
[blue mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(spView).mas_offset(10);
make.right.mas_equalTo(red.mas_left).mas_offset(-10);
// make.top.mas_equalTo(spView).mas_offset(50); //方法1
make.top.mas_equalTo(red.mas_top); //方法2
}];
*/
/*
//方式 5 中间对齐
UILabel *nameLab = [UILabel new];
nameLab.text = @"黄药师";
nameLab.font = JHFont(30);
nameLab.backgroundColor = [UIColor yellowColor];
[spView addSubview:nameLab];
UILabel *jobLab = [UILabel new];
jobLab.text = @"桃花岛岛主";
jobLab.font = JHFont(20);
jobLab.backgroundColor = [UIColor orangeColor];
[spView addSubview:jobLab];
UILabel *nickLab = [UILabel new];
nickLab.text = @"“天下五绝”之“东邪”";
nickLab.font = JHFont(10);
nickLab.backgroundColor = [UIColor brownColor];
[spView addSubview:nickLab];
[nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.mas_equalTo(spView).mas_offset(10);
make.right.mas_equalTo(jobLab.mas_left).mas_offset(-10);
}];
[jobLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(nameLab.mas_right);
make.right.mas_equalTo(nickLab.mas_left).mas_offset(-10);
make.centerY.mas_equalTo(nameLab.mas_centerY);
}];
[nickLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(jobLab.mas_right);
make.right.mas_equalTo(spView).mas_offset(-10);
make.centerY.mas_equalTo(nameLab.mas_centerY);
}];
*/
/*
//更新约束,动画效果
[self.blue mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(200);
}];
[UIView animateWithDuration:1 animations:^{
[self.view layoutIfNeeded];
}];
*/