Jerry
Jerry

Reputation: 927

iOS AutoLayout with masonry, failed to set child's bottom equal to parent bottom

I have a parent view which is red on the screen, and inside it, there is a child view which is green. When trying position child to left-bottom corner, code below failed.

    [superView addSubview:self];
    self.backgroundColor = [UIColor redColor];
    [self makeConstraints:^(MASConstraintMaker *make) {
        make.width.left.top.equalTo(superView);
        make.height.mas_equalTo(50);
    }];

    UIView *header = [[UIView alloc] init];
    [self addSubview:header];
    header.backgroundColor = [UIColor greenColor];
    [header makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(30);
        make.bottom.equalTo(self);
    }];

enter image description here

How to fix this issue?

Upvotes: 0

Views: 273

Answers (1)

JingJingTao
JingJingTao

Reputation: 1790

If you try set the leading constraint for the header view, e.g.

mas.leading.equalTo(@0);

Upvotes: 0

Related Questions