<legend id='DKeVi'><style id='DKeVi'><dir id='DKeVi'><q id='DKeVi'></q></dir></style></legend>

<i id='DKeVi'><tr id='DKeVi'><dt id='DKeVi'><q id='DKeVi'><span id='DKeVi'><b id='DKeVi'><form id='DKeVi'><ins id='DKeVi'></ins><ul id='DKeVi'></ul><sub id='DKeVi'></sub></form><legend id='DKeVi'></legend><bdo id='DKeVi'><pre id='DKeVi'><center id='DKeVi'></center></pre></bdo></b><th id='DKeVi'></th></span></q></dt></tr></i><div id='DKeVi'><tfoot id='DKeVi'></tfoot><dl id='DKeVi'><fieldset id='DKeVi'></fieldset></dl></div>

    <small id='DKeVi'></small><noframes id='DKeVi'>

    1. <tfoot id='DKeVi'></tfoot>
        <bdo id='DKeVi'></bdo><ul id='DKeVi'></ul>
      1. 如何将 3 个 UIButtons 对齐到 UITableCellView 的中心?

        How can I align 3 UIButtons to the center of an UITableCellView?(如何将 3 个 UIButtons 对齐到 UITableCellView 的中心?)
          <bdo id='XSd9X'></bdo><ul id='XSd9X'></ul>
          • <legend id='XSd9X'><style id='XSd9X'><dir id='XSd9X'><q id='XSd9X'></q></dir></style></legend>

            1. <i id='XSd9X'><tr id='XSd9X'><dt id='XSd9X'><q id='XSd9X'><span id='XSd9X'><b id='XSd9X'><form id='XSd9X'><ins id='XSd9X'></ins><ul id='XSd9X'></ul><sub id='XSd9X'></sub></form><legend id='XSd9X'></legend><bdo id='XSd9X'><pre id='XSd9X'><center id='XSd9X'></center></pre></bdo></b><th id='XSd9X'></th></span></q></dt></tr></i><div id='XSd9X'><tfoot id='XSd9X'></tfoot><dl id='XSd9X'><fieldset id='XSd9X'></fieldset></dl></div>
                <tbody id='XSd9X'></tbody>

                <tfoot id='XSd9X'></tfoot>

                  <small id='XSd9X'></small><noframes id='XSd9X'>

                • 本文介绍了如何将 3 个 UIButtons 对齐到 UITableCellView 的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何将 3 个 UIButton 对齐到 UITableCellView 的中心?

                  How can I align 3 UIButtons to the center of an UITableCellView?

                  例如说我有 3 个带有标题的 UIButton:

                  For example say I have 3 UIButtons with titles:

                  1. 电子邮件
                  2. 电话
                  3. Skype

                  可以隐藏一个或多个 UIButton.例如,如果电话 UIButton 被隐藏,那么只有电子邮件和 Skype 应该居中对齐.如果电话和 Skype 被隐藏,那么只有电子邮件应该居中对齐.

                  It is possible for one or more of the UIButtons to be hidden. For example, if the Phone UIButton is hidden then only Email and Skype should be aligned in the center. If Phone and Skype is hidden then only Email should be aligned in the center.

                  当任何 UIButton 被隐藏时,可见的应该居中对齐.

                  When any of the UIButtons are hidden, the visible ones should be aligned in the center.

                  我想将它们水平和垂直居中.

                  I want to center them both horizontally and vertically.

                  推荐答案

                  已针对 xcode 7 测试:

                  我想你正在寻找类似的东西

                  i suppose your are looking for something like that

                  解决方案:

                  步骤:1) 所需要的是一个封装视图,它将所有三个按钮(Skype、电话、电子邮件)保持在中心,而不管里面是否有一个按钮、两个或三个按钮.为此,创建了一个持有人视图,在下面的快照中以绿色背景显示.

                  Steps: 1) what is needed is an encapsulating view which holds all three buttons (skype, phone, email) into center irrespective of whether there is one button, two or three inside it. For that a holder view is created which is shown with green background in below snapshot.

                  该持有人视图的约束是

                  它只是保存所有的子视图,它会从它的内容中获取它的大小,所以不需要给它高度/宽度限制.

                  it is just to hold all the subviews, it will get its size from its content so no need to give it height/width constraints.

                  2) 现在中心按钮的约束将是

                  2) now constraints for the button in the center will be

                  3) 两侧按钮的约束将是

                  如果您需要隐藏任何按钮,只需将其宽度约束设置为 0,所有其他按钮将相应地重新排列

                  对于 TableView 单元格:

                      @IBOutlet weak var emailButtonWidthConstraint : NSLayoutConstraint?
                      @IBOutlet weak var phoneButtonWidthConstraint : NSLayoutConstraint?
                      @IBOutlet weak var skypeButtonWidthConstraint : NSLayoutConstraint?
                  
                      func showButtons(showSkype showSkype : Bool, showEmail : Bool, showPhone : Bool ){
                          emailButtonWidthConstraint?.constant = showEmail ? 54.0 : 0.0
                          phoneButtonWidthConstraint?.constant = showPhone ? 54.0 : 0.0
                          skypeButtonWidthConstraint?.constant = showSkype ? 54.0 : 0.0
                  
                          self.layoutIfNeeded()
                      }
                  

                  用途:

                      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
                          let cell = tableView.dequeueReusableCellWithIdentifier("customCell", forIndexPath: indexPath) as? CustomCell
                  
                          if indexPath.row == 0 {
                              cell?.showButtons(showSkype: true, showEmail: true, showPhone: true)
                          } else if indexPath.row == 1 {
                              cell?.showButtons(showSkype: false, showEmail: true, showPhone: true)
                          } else if indexPath.row == 2 {
                              cell?.showButtons(showSkype: true, showEmail: false, showPhone: true)
                          } else if indexPath.row == 3 {
                              cell?.showButtons(showSkype: true, showEmail: true, showPhone: false)
                          } else if indexPath.row == 4 {
                              cell?.showButtons(showSkype: false, showEmail: false, showPhone: true)
                          } else if indexPath.row == 5 {
                              cell?.showButtons(showSkype: false, showEmail: true, showPhone: false)
                          } else if indexPath.row == 6 {
                              cell?.showButtons(showSkype: true, showEmail: false, showPhone: false)
                          } else {
                              cell?.showButtons(showSkype: true, showEmail: true, showPhone: true)
                          }
                  
                          return cell!
                      }
                  

                  使用 UIStackView 也可以实现同样的效果(显然没有这些令人头疼的问题),但它不会在 9.0 之前的 iOS 上运行

                  Same can be achieved with UIStackView (without all this headache obviously) but that won't run on iOS prior to 9.0

                  更新(2015 年 10 月 26 日):

                  GitHub Repo 用于测试项目

                  这篇关于如何将 3 个 UIButtons 对齐到 UITableCellView 的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  UIButton title text color(UIButton 标题文本颜色)
                  Stretch background image for UIButton(为 UIButton 拉伸背景图像)
                  Using Tint color on UIImageView(在 UIImageView 上使用 Tint 颜色)
                  How can I change UIButton title color?(如何更改 UIButton 标题颜色?)
                  iPhone UIButton - image position(iPhone UIButton - 图像位置)
                  UIButton remove all target-actions(UIButton 删除所有目标动作)
                  <tfoot id='U30iU'></tfoot>

                  <i id='U30iU'><tr id='U30iU'><dt id='U30iU'><q id='U30iU'><span id='U30iU'><b id='U30iU'><form id='U30iU'><ins id='U30iU'></ins><ul id='U30iU'></ul><sub id='U30iU'></sub></form><legend id='U30iU'></legend><bdo id='U30iU'><pre id='U30iU'><center id='U30iU'></center></pre></bdo></b><th id='U30iU'></th></span></q></dt></tr></i><div id='U30iU'><tfoot id='U30iU'></tfoot><dl id='U30iU'><fieldset id='U30iU'></fieldset></dl></div>
                    <tbody id='U30iU'></tbody>
                      • <legend id='U30iU'><style id='U30iU'><dir id='U30iU'><q id='U30iU'></q></dir></style></legend>
                          <bdo id='U30iU'></bdo><ul id='U30iU'></ul>

                            <small id='U30iU'></small><noframes id='U30iU'>