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

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

      2. <tfoot id='dcVkw'></tfoot>
        • <bdo id='dcVkw'></bdo><ul id='dcVkw'></ul>

        UIStackView 分布填充均等

        时间:2023-09-11
          • <bdo id='ppDTY'></bdo><ul id='ppDTY'></ul>
            • <i id='ppDTY'><tr id='ppDTY'><dt id='ppDTY'><q id='ppDTY'><span id='ppDTY'><b id='ppDTY'><form id='ppDTY'><ins id='ppDTY'></ins><ul id='ppDTY'></ul><sub id='ppDTY'></sub></form><legend id='ppDTY'></legend><bdo id='ppDTY'><pre id='ppDTY'><center id='ppDTY'></center></pre></bdo></b><th id='ppDTY'></th></span></q></dt></tr></i><div id='ppDTY'><tfoot id='ppDTY'></tfoot><dl id='ppDTY'><fieldset id='ppDTY'></fieldset></dl></div>

              1. <legend id='ppDTY'><style id='ppDTY'><dir id='ppDTY'><q id='ppDTY'></q></dir></style></legend>
              2. <small id='ppDTY'></small><noframes id='ppDTY'>

                  <tbody id='ppDTY'></tbody>

                  <tfoot id='ppDTY'></tfoot>
                  本文介绍了UIStackView 分布填充均等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以,我有一个 UIStackView,其中包含四 (4) 个 UIView.如果我删除其中一 (1) 个 UIView,其他三 (3) 个将填满 UIStackView 中的整个空间.

                  So, I have a UIStackView that contains four (4) UIViews. If I remove one (1) of those UIViews, the other three (3) will fill the entire space in the UIStackView.

                  我的问题:

                  如何在 UIView 上添加最大高度,这样即使分布被平均填充,它也不会填满 UIStackView 的整个空间?我读了一些关于添加约束的东西,但我无法让它工作.顺便说一句,我正在使用 swift.

                  How can I add a max height on a UIView so that it won't fill the entire space of the UIStackView even though the distribution is filled equally? I read something about adding a constraint but I'm not able to make it work. I'm using swift by the way.

                  谢谢.

                  推荐答案

                  作为确认,这是当前的行为:

                  As a confirmation, this is the current behavior:

                  这就是你要的:

                  为了实现它,你可以遵循这个简单的技巧:

                  In order to achieve it, you could follow this simple trick:

                  附注:我假设您为堆栈视图添加了所需的适当约束.

                  P.S: I assume that you added the needed appropriate constraints for your stack view.

                  如果您的堆栈视图没有 "height" 约束,请添加一个:

                  If your stack view doesn't have a "height" constraint, add one:

                  现在,将其作为 IBOutlet 添加到分配的 ViewController;在我的示例中,我将其称为 stackHeight:

                  Now, add it as an IBOutlet to the assigned ViewController; In my example, I'm calling it stackHeight:

                  @IBOutlet weak var stackHeight: NSLayoutConstraint!
                  

                  如果您想隐藏视图(在我的示例中,我根据分配给自身的 IBAction 隐藏橙色按钮,点击它时应该隐藏),您需要从 stackHeight.constant 中获取要隐藏和减去的视图高度:

                  On the event that you want to hide the view (in my example, I'm hiding the orange button based on IBAction assigned to itself, when tapping on it, should be hidden), you need to get the height of the view that you want to hide and subtract from stackHeight.constant:

                      @IBAction func orangeTapped(_ sender: AnyObject) {
                          orange.isHidden = true
                  
                          // here we go:
                          stackHeight.constant = stackHeight.constant - orange.frame.size.height
                      }
                  

                  这篇关于UIStackView 分布填充均等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:AutoLayout + RTL + UILabel 文本对齐 下一篇:自动布局 - 使视图高度相对于超级视图的一半高度

                  相关文章

                  <tfoot id='JVW1d'></tfoot>
                • <legend id='JVW1d'><style id='JVW1d'><dir id='JVW1d'><q id='JVW1d'></q></dir></style></legend>

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

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