美文网首页
Masony子视图撑起父视图高度

Masony子视图撑起父视图高度

作者: OrrHsiao | 来源:发表于2021-05-31 11:57 被阅读0次

父视图不约束宽高,子视图设置好距离父视图的各边边距,并指定子视图的宽高(两者缺一不可)。
父视图

    UIView *superView = [[UIView alloc] init];
    [superView setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:superView];
    [superView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.centerY.equalTo(self.view.mas_centerY);
    }];

子视图

    UIView *childView = [[UIView alloc] init];
    [childView setBackgroundColor:[UIColor grayColor]];
    [superView addSubview:childView];
    [childView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(10);
        make.right.bottom.offset(-10);
        make.width.height.offset(100);
    }];

相关文章

网友评论

      本文标题:Masony子视图撑起父视图高度

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