-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fully support NS/UILayoutGuide and SwiftPM #594
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example center two labels: UILayoutGuide *box = [[UILayoutGuide alloc] init];
[self.view addLayoutGuide:box];
[box mas_makeConstraints:^(id<MASLayoutConstraint> _Nonnull make) {
make.centerX.mas_equalTo(self.view.mas_centerX);
make.centerY.mas_equalTo(self.view.mas_centerY);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleLargeTitle];
titleLabel.text = @"title";
[self.view addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(box.mas_top);
make.centerX.mas_equalTo(box.mas_centerX);
}];
UILabel *descrLabel = [[UILabel alloc] init];
descrLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
descrLabel.text = @"descr";
[self.view addSubview:descrLabel];
[descrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(box.mas_centerX);
make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(8);
make.bottom.mas_equalTo(box.mas_bottom);
}]; Or more simple: UILayoutGuide *box = [[UILayoutGuide alloc] init];
[self.view addLayoutGuide:box];
[box mas_makeConstraints:^(id<MASLayoutConstraint> _Nonnull make) {
make.center.mas_equalTo(0);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleLargeTitle];
titleLabel.text = @"title";
[self.view addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(box);
make.centerX.mas_equalTo(box.mas_centerX);
}];
UILabel *descrLabel = [[UILabel alloc] init];
descrLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
descrLabel.text = @"descr";
[self.view addSubview:descrLabel];
[descrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(box);
make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(8);
make.bottom.mas_equalTo(box);
}]; |
cntrump
force-pushed
the
master
branch
3 times, most recently
from
May 30, 2021 16:05
e983a38
to
2dfd239
Compare
All done. |
2 tasks
This was referenced May 31, 2021
cntrump
changed the title
Add MASLayoutGuide for UI/NSLayoutGuide support
Fully support UI/NSLayoutGuide
May 31, 2021
cntrump
changed the title
Fully support UI/NSLayoutGuide
Fully support NS/UILayoutGuide
May 31, 2021
cntrump
force-pushed
the
master
branch
2 times, most recently
from
May 31, 2021 14:56
75709d2
to
25fdb85
Compare
cntrump
force-pushed
the
master
branch
2 times, most recently
from
May 31, 2021 22:54
a9beeeb
to
af0bde8
Compare
Example UITableViewCell with UILayoutGuide @implementation Cell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
UILayoutGuide *box = [[UILayoutGuide alloc] init];
[self.contentView addLayoutGuide:box];
[box mas_makeConstraints:^(MASConstraintMaker * _Nonnull make) {
make.edges.mas_equalTo(self.contentView.mas_safeAreaLayoutGuide).inset(24);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleLargeTitle];
titleLabel.text = @"title";
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(box);
}];
UILabel *descrLabel = [[UILabel alloc] init];
descrLabel.numberOfLines = 0;
descrLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
descrLabel.text = @"descrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescrdescr";
[self.contentView addSubview:descrLabel];
[descrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(8);
make.left.right.bottom.mas_equalTo(box);
}];
}
return self;
} |
cntrump
changed the title
Fully support NS/UILayoutGuide
Fully support NS/UILayoutGuide and SwiftPM
Jun 1, 2021
Transfer to #595 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Example
frameLayoutGuide
&contentLayoutGuide
: