美文网首页
UI框架Masonry 二

UI框架Masonry 二

作者: 禄子_c79b | 来源:发表于2019-03-20 10:16 被阅读0次

//设置约束

  • (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block;

//如果之前已经有约束,则更新新的约束,如果没有约束,则添加约束

  • (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block;

//将之前的约束全部删除,添加新的约束

  • (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;

//添加两个控件
UIView *blueView = [[UIView alloc] init];
blueView.backgroundColor = [UIColor blueColor];
blueView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:blueView];

UIView *redView = [[UIView alloc] init];
redView.backgroundColor = [UIColor redColor];
redView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:redView];

//给蓝色View设置约束
[blueView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(self.view.mas_left).offset(30);//和父view的左边间距为30;
    make.bottom.equalTo(self.view.mas_bottom).offset(-30);//和父view的底部间距为30;
    make.right.equalTo(redView.mas_left).offset(-30);//和红色view的间距为30;
    make.height.mas_equalTo(50);//蓝色view的高度为50
}];

//给红色View设置约束
[redView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.equalTo(self.view.mas_right).offset(-30);//和父view的右边间距为30;
    make.bottom.equalTo(blueView.mas_bottom);//和蓝色view的底部对齐
    make.height.equalTo(blueView.mas_height);//和蓝色view的高度相等
    make.width.equalTo(blueView.mas_width);//和蓝色view的宽度相等
}];
效果图: image

相关文章

网友评论

      本文标题:UI框架Masonry 二

      本文链接:https://www.haomeiwen.com/subject/uinamqtx.html