• <small id='PZlZb'></small><noframes id='PZlZb'>

    1. <legend id='PZlZb'><style id='PZlZb'><dir id='PZlZb'><q id='PZlZb'></q></dir></style></legend>
      <tfoot id='PZlZb'></tfoot>

          <bdo id='PZlZb'></bdo><ul id='PZlZb'></ul>
      1. <i id='PZlZb'><tr id='PZlZb'><dt id='PZlZb'><q id='PZlZb'><span id='PZlZb'><b id='PZlZb'><form id='PZlZb'><ins id='PZlZb'></ins><ul id='PZlZb'></ul><sub id='PZlZb'></sub></form><legend id='PZlZb'></legend><bdo id='PZlZb'><pre id='PZlZb'><center id='PZlZb'></center></pre></bdo></b><th id='PZlZb'></th></span></q></dt></tr></i><div id='PZlZb'><tfoot id='PZlZb'></tfoot><dl id='PZlZb'><fieldset id='PZlZb'></fieldset></dl></div>
      2. 设置 UIView 大小以适应子视图

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

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

          <tbody id='rb5o7'></tbody>
          • <tfoot id='rb5o7'></tfoot>

              1. <legend id='rb5o7'><style id='rb5o7'><dir id='rb5o7'><q id='rb5o7'></q></dir></style></legend>

                • <bdo id='rb5o7'></bdo><ul id='rb5o7'></ul>
                • 本文介绍了设置 UIView 大小以适应子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 UIView,其中包含两个具有动态高度的 UILabel.我希望 UIView 适合 UILabel 的大小 + 一些填充.现在我正在绘制标签,然后将 UIView 的宽度和高度约束设置为标签的组合大小.

                  I'm having a UIView that's containing two UILabels, which have dynamic heights. I want the UIView to fit the size of the UILabels + some padding. Right now I'm drawing the labels and then sets the UIView's width and height constraints to the combined size of the labels.

                  现在我正在这样做:

                  func populateWithMessage(headline: String?, message: String) {
                      // Sets text
                      self.headerLabel.text = headline
                      self.messageLabel.text = message
                  
                      self.headerLabel.sizeToFit()
                      self.messageLabel.sizeToFit()
                  
                      self.layoutSubviews()
                  
                      // Finding the label with the greatest width
                      var longestLabel: UILabel!
                      if self.headerLabel.frame.width > self.messageLabel.frame.width {
                         longestLabel = self.headerLabel
                     } else {
                         longestLabel = self.messageLabel
                     }
                     
                     let combinedLabelHeight = self.headerLabel.frame.height + self.messageLabel.frame.height
                     
                     // Update the container view's constraints
                     self.containerViewWidtConstraint.constant = longestLabel.frame.width + 10
                     self.containerViewHeightConstraint.constant = combinedLabelHeight + 10
                  
                     self.updateConstraints()
                  }
                  

                  不幸的是,它不起作用.我正在使用 Swift 2.3 和 Autolayout.

                  Unfortunately it doesn't work. I'm using Swift 2.3 and Autolayout.

                  推荐答案

                  您可以使用情节提要本身来完成.

                  You can do it using the storyboard itself.

                  将视图的底部约束设置为第二个 UIlabel.所以当label的高度增加时,UIView的高度也会增加.

                  Set the View's bottom constraint to second UIlabel. So when the height of label increases, UIView's height will also increases.

                  这篇关于设置 UIView 大小以适应子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:调用 layoutIfNeeded() 时 AutoLayout 会破坏约束 下一篇:自动布局约束警告“将尝试通过打破约束来恢复"

                  相关文章

                • <legend id='Prkl4'><style id='Prkl4'><dir id='Prkl4'><q id='Prkl4'></q></dir></style></legend>

                    <tfoot id='Prkl4'></tfoot>
                  1. <small id='Prkl4'></small><noframes id='Prkl4'>

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