我正在更新一个最初在底部有一个按钮的屏幕。我的任务是使用 Masonry 框架渲染底部居中的两个按钮,它是一个 AutoLayout 包装器。
我想让两个按钮在底部居中并并排。这是我想出的:
代码如下:
- (void)createConstraints {
// Map View
[self.mapView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.and.right.equalTo(self);
make.bottom.equalTo(self.mas_centerY).multipliedBy(0.9);
}];
// Information TextView
[self.informationTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mapView.mas_bottom); //.with.offset(kTableViewCellPadding);
make.left.and.right.equalTo(self);
make.bottom.equalTo(self.editSiteButtonBackground.mas_top);//.with.offset(-kTableViewCellPadding);
}];
// Edit Site Button Background
[self.editSiteButtonBackground mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.bottom.and.right.equalTo(self);
make.height.equalTo(@54);
}];
// Add Site Comments Button Background
[self.addSiteCommentsButtonBackground mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.editSiteButton.mas_right);
make.bottom.equalTo(self.editSiteButton);
make.height.equalTo(@54);
}];
// Edit Site Button
[self.editSiteButton mas_makeConstraints:^(MASConstraintMaker *make) {
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
make.edges.equalTo(self.editSiteButtonBackground).with.insets(padding).with.priorityHigh();
make.width.lessThanOrEqualTo(@260);
make.centerX.equalTo(self.editSiteButtonBackground);
}];
// Add Site Comments Button
[self.addSiteCommentsButton mas_makeConstraints:^(MASConstraintMaker *make) {
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
make.edges.equalTo(self.addSiteCommentsButtonBackground).with.insets(padding).with.priorityHigh();
make.width.lessThanOrEqualTo(@270);
make.top.equalTo(self.addSiteCommentsButton);
make.centerX.equalTo(self.addSiteCommentsButtonBackground);
}];
// Navigation
[self.navigationButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.mapView).with.offset(-20);
make.bottom.equalTo(self.mapView).with.offset(-20);
}];
}
如何并排显示按钮并在底部居中显示?
最佳答案
很抱歉,我无法以编程方式向您说明,但如果我说的话,
如果设计的是 Storyboard或 XIB,您可以直接使用拖放功能进行设计。
使“添加站点评论”按钮垂直居中于“编辑站点”按钮,并在两个按钮之间留出水平空间。
希望对你有所帮助。
谢谢。
关于ios - 如何使用 iOS Masonry(自动布局)将两个按钮放置在彼此旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41215495/