1.安装Masonry库
pod 'Masonry'
2.导入Masonry
import <Masonry/Masonry.h>
3.使用
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *btn = [[UIButton alloc] init];
btn.backgroundColor = [UIColor redColor];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.view).with.mas_offset(10);
make.right.mas_equalTo(self.view).with.mas_offset(-10);
make.top.mas_equalTo(self.view).with.mas_offset(100);
make.height.mas_equalTo(@100);
}];
}
- (void)btnClick:(UIButton *)btn {
[UIView animateWithDuration:3 animations:^{
[btn mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(@300);
}];
[self.view layoutIfNeeded];
}];
}
完毕。