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

      1. <small id='L5vbx'></small><noframes id='L5vbx'>

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

      3. <tfoot id='L5vbx'></tfoot>

        具有动态高度多个UILabel的UIView

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

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

                1. 本文介绍了具有动态高度多个UILabel的UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在制作一个包含 2 个 UILabel 的自定义 UIView,每个 UILabel 都具有动态高度.我无法为动态高度设置约束.(我是 Auto-Layout 和 iOS 方面的新手).

                  两个 UILabel 从 Top &底部,并与超级视图水平对齐.当我更改 UILabel 之一的内容时,UIView 和 UILabel 不会根据需要调整大小.

                  请提出建议.附上当前约束的屏幕截图.

                  解决方案

                  我根据你的要求为你做了一个demo.从下面的链接下载它,

                  第 2 步:- 将约束设置为标签 1

                  1) 领先 2) 前 3) 尾随(来自它的超级视图)

                  第 3 步:- 将约束设置为标签 2

                  1) 领先 2) 前 3) 尾随(来自它的超级视图)

                  第 4 步:- 最棘手的从 UIView 给 UILabel 底部.

                  在 Xcode 10 及更高版本中 - 选择您的 UIView 和标签,然后从对齐约束部分选择底部边缘约束.

                  第 5 步:-(可选)将约束设置为 UIButton

                  1) 领先 2) 底部 3) 尾随 4) 固定高度(从主视图)

                  输出:-

                  注意:-请确保您已在 Label 属性中设置 Number of lines =0.

                  Edit1 :- 如果您想使用 BottomConstrain (>=) 增加尺寸,请查看下面的图片.

                  我希望这些信息足以理解 Autoresize UIView 根据 UILabel 的高度和 Autoresize UILabel 根据文本.

                  I'm making a custom UIView with 2 UILabel in it, with each UILabel having dynamic height. I'm unable to set constraints for dynamic height. (I'm new to Auto-Layout & iOS stuff).

                  Both UILabels are connected to each other from Top & Bottom, and are Horizontally aligned to superview. And when I change content of one of the UILabel, UIView and UILabel does not resize as required.

                  Please suggest. Attaching screenshots for current constraints.

                  解决方案

                  I made a demo for you according to your requirement. Download it from below link,

                  Autoresize UIView and UILabel

                  Step by Step Guide :-

                  Step 1 :- Set constrain to UIView

                  1) Leading 2) Top 3) Trailing (From mainview)

                  Step 2 :- Set constrain to Label 1

                  1) Leading 2) Top 3) Trailing (From it's superview)

                  Step 3 :- Set constrain to Label 2

                  1) Leading 2) Top 3) Trailing (From it's superview)

                  Step 4 :- Most tricky give bottom to UILabel from UIView.

                  In Xcode 10 and above - Select your UIView and Label after that from the Align Constraint section select Bottom Edges constraint.

                  Step 5 :- (Optional) Set constrain to UIButton

                  1) Leading 2) Bottom 3) Trailing 4) Fixed Height (From mainview)

                  Output :-

                  Note :- Make sure you have set Number of lines =0 in Label property.

                  Edit1 :- If you want to increase size with BottomConstrain (>=) please check below Image.

                  I hope this info enough to understand Autoresize UIView according to UILabel's height and Autoresize UILabel According to text.

                  这篇关于具有动态高度多个UILabel的UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:自动布局和程序约束:如何处理多次触发的 updateConstraints? 下一篇:每次 Xcode 重新启动时视图错位

                  相关文章

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

                  1. <small id='shzah'></small><noframes id='shzah'>

                  2. <legend id='shzah'><style id='shzah'><dir id='shzah'><q id='shzah'></q></dir></style></legend>