ios - 如何使用 iOS Masonry(自动布局)将两个按钮放置在彼此旁边

标签 ios objective-c masonry-ios-osx

我正在更新一个最初在底部有一个按钮的屏幕。我的任务是使用 Masonry 框架渲染底部居中的两个按钮,它是一个 AutoLayout 包装器。

我想让两个按钮在底部居中并并排。这是我想出的:

enter image description here

代码如下:

- (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/

相关文章:

ios - 以编程方式(使用 SnapKit)构建 UI 时如何正确使用大小类?

ios - 如何快速检查 JSON 是否为空?

ios - UITableViewCell 中的两个堆叠动态高度标签

ios - 如何将 Firebase 下载文件与进度 View 链接?

iOS >> 协议(protocol)和委托(delegate)概念

iphone - 如何将 UIBarButtonItem 添加到其中包含文本和图像的 UIToolbar?

ios - AFNetworking AFHTTPSessionManager POST 调用了两次

ios - 多个动态原型(prototype)单元的索引路径

ios - 使用 Masonry 在它的 super View 中居中 View