Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多控件居中 #563

Open
2 tasks
Wenjie-Qin opened this issue Jul 15, 2019 · 1 comment
Open
2 tasks

多控件居中 #563

Wenjie-Qin opened this issue Jul 15, 2019 · 1 comment

Comments

@Wenjie-Qin
Copy link

New Issue Checklist

🚫 If this template is not filled out your issue will be closed with no comment. 🚫

  • I have looked at the Documentation
  • I have filled out this issue template.

Issue Info

Info Value
Platform e.g. ios/osx/tvos
Platform Version e.g. 8.0
Masonry Version e.g. 1.0
Integration Method e.g. carthage/cocoapods/manually

Issue Description

⚠️ Replace this with the description of your issue. ⚠️

@cntrump
Copy link
Contributor

cntrump commented Jun 1, 2021

#594

UILayoutGuide *contentLayoutGuide = [[UILayoutGuide alloc] init];
[self.view addLayoutGuide:contentLayoutGuide];
[contentLayoutGuide mas_makeConstraints:^(id<MASLayoutConstraint>  _Nonnull make) {
    make.center.mas_equalTo(0);
    make.width.mas_equalTo(self.view);
}];

NSArray<UIColor *> *colors = @[
    UIColor.redColor,
    UIColor.yellowColor,
    UIColor.blueColor,
    UIColor.greenColor
];

UIView *prev = nil;
NSInteger count = 4;

for (NSInteger i = 0; i < count; i++) {
    UIView *v = [[UIView alloc] init];
    v.backgroundColor = colors[i % 4];
    [self.view addSubview:v];
    [v mas_makeConstraints:^(MASConstraintMaker *make) {
        if (i == 0) {
            make.top.mas_equalTo(contentLayoutGuide).offset(24);
        } else {
            make.top.mas_equalTo(prev.mas_bottom).offset(8);
        }

        make.centerX.equalTo(contentLayoutGuide);

        make.height.mas_equalTo(80);
        make.width.mas_equalTo(contentLayoutGuide).offset(-24);

        if (i == count - 1) {
            make.bottom.mas_equalTo(contentLayoutGuide).offset(-24);
        }
    }];

    prev = v;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants