<tfoot id='uRkGa'></tfoot>

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

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

      自动布局以动态调整 uilabel 宽度

      时间:2023-09-11
      • <legend id='jbyWx'><style id='jbyWx'><dir id='jbyWx'><q id='jbyWx'></q></dir></style></legend>

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

          <tbody id='jbyWx'></tbody>

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

              1. 本文介绍了自动布局以动态调整 uilabel 宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                所以我在 Storyboard 中有两个并排的 UILabel.第二个标签应与第一个标签的右边缘对接(尾随约束为 1),但我还需要第一个标签(左侧的标签)将其宽度设置为等于其内容大小,除非它达到最大宽度.视觉上:

                So I have two UILabels side by side in Storyboard. The second label should butt up against the right edge of the first one (trailing constraint of 1), but I also need the first label (the one on the left) to set it's width equal to it's content size unless it hits a max width. Visually:

                |标记一个文本||标记两个文本|

                |Label one text| |Label two text|

                我需要以下约束:

                1) 除非达到最大尺寸,否则标签一应调整宽度.

                1) Label one should resize width wise unless it hits a max size.

                2) 标签二应始终与标签一的右边缘对接

                2) Label two should always be butted up against the right edge of label one

                如何在 Storyboard 中进行设置?

                How do I set this up in Storyboard?

                推荐答案

                1. 在标签之间创建 1 点水平空间:按住 Control 键从 label2 拖动到 label1.从弹出窗口中选择水平间距.双击约束.将常数更改为 1.
                2. label1 一个最大宽度:选择 label1.转到顶部菜单栏,选择编辑器 > 引脚 > 宽度.双击约束.将关系更改为 <= 并将常量更改为最大宽度.
                3. 垂直对齐标签:选择两个标签.转到顶部菜单栏,选择编辑器 > 对齐 > 垂直中心.
                4. 您仍然需要设置约束来定义标签在其容器视图中的位置.我把它留给你.我将 label1 固定在距根视图左边缘 32 点处,距顶部布局指南 34 点处.
                5. 更新标签的框架,使其反映上述约束:转到画布右下角的菜单栏.点击解决自动布局问题"Tie-Fighter 按钮.在弹出窗口中选择更新所有帧...".
                1. Create the 1 point horizontal space between the labels: Control-drag from label2 to label1. Choose Horizontal Spacing from the pop-up. Double click the constraint. Change the constant to 1.
                2. Give label1 a max width: Select label1. Go to the top menu bar, select Editor > Pin > Width. Double click the constraint. Change the relationship to <= and change the constant to the max width.
                3. Vertically align the labels: Select both labels. Go to the top menu bar, select Editor > Align > Vertical Centers.
                4. You still need to set constraints that define how your labels are positioned in their container view. I leave that up to you. I pinned label1 32 points from the left edge of the root view and 34 points from top layout guide.
                5. Update the frames of the labels so they reflect the above constraints: Go to the menu bar in the lower right-hand corner of the canvas. Tap the "Resolve Auto Layout Issues" Tie-Fighter button. Select "Update All Frames…" in the pop-up.

                注意:请注意,我不必创建约束来使 label1 的宽度反映其内容大小.内容大小约束是自动生成的.

                Note: Notice that I did not have to create constraints to make label1's width reflect its content size. The content sizing constraints are generated automatically.

                这篇关于自动布局以动态调整 uilabel 宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在运行时更改标签约束? 下一篇:键入时调整 UITextField 的大小(使用自动布局)

                相关文章

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

                  <small id='5M5DC'></small><noframes id='5M5DC'>

                    <legend id='5M5DC'><style id='5M5DC'><dir id='5M5DC'><q id='5M5DC'></q></dir></style></legend>