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

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

      1. <tfoot id='GEzzD'></tfoot>
          <bdo id='GEzzD'></bdo><ul id='GEzzD'></ul>

        iOS - 将两个标签放在其超级视图的中心

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

              <bdo id='Y0hVK'></bdo><ul id='Y0hVK'></ul>
                • <small id='Y0hVK'></small><noframes id='Y0hVK'>

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

                  本文介绍了iOS - 将两个标签放在其超级视图的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两个标签,L1 和 L2,长度可变且不相同.我想在 Xcode 中使用约束放置这两个标签.如果可能的话,我不想以编程方式操纵约束.将不胜感激.

                  I have two label, L1 and L2 of variable and nonidentical length. I want to place these two label using constraints in Xcode. If possible i don't want to manipulate constraints programmatically. guidance will be appreciated.

                  正确的图像应该是预期的输出

                  Right image should be the expected output

                  要求,

                  1. 两个标签的宽度不相同
                  2. 当运行 L1 的前导空格和 L2 的尾随空格时将相等
                  3. L1 和 L1 之间的距离L2,水平间距固定,10 px
                  4. UIStackView 无法使用

                  我怎样才能从 Xcode 中做到这一点?

                  How can I do it from Xcode?

                  推荐答案

                  你可以做的是将 UILabel 放在 UIView 中,然后:

                  What you can do is put both the UILabel inside a UIView and then:

                  • HEL UILabelsuperView 中添加前导、顶部和底部.
                  • superView 的尾随、顶部和底部添加到您的 HEAVENLY UILabel.
                  • 在两个 UILabel
                  • 之间添加 10 磅的水平间距
                  • Add a leading, top and bottom to the superView to your HEL UILabel.
                  • Add a trailing, top and bottom to the superView to your HEAVENLY UILabel.
                  • Add a horizontal spacing of 10 points between your two UILabel

                  现在您的 UIView 水平和垂直居中在屏幕中间.将水平居中约束优先级设置为 250.使用 >= 5 约束将 UIView 的前导和尾随空格添加到其 superView

                  Now center your UIView horizontally and vertically in the middle of the screen. Set the horizontally in center constraint priority to 250. Add a leading and trailing space of your UIView to its superView with a >= 5 constraint

                  此外,如果文本太大,则上述约束不足以完美运行(您必须将 numberOfLines 设置为 0 并且 wrap modewordWrap 以显示完整的文本并转到下一行,当然)!因为 UILabelinferred heightinferred width 的优先级为 750,每个 UILabel 的内容抗压缩优先级 默认也是 750,Xcode 会很困惑该怎么做,这是理所当然的!您可以做的是将 attributes inspector 中的 content compression 属性设置为 1000

                  Additionally if the text is too large then the above constraints aren't simply enough to work perfectly (You will have to set the numberOfLines to 0 and wrap mode to wordWrap to display the complete text and go to the next line, of course)! As the UILabels will have their inferred height and inferred width with a priority of 750 and the content compression resistance priority of each UILabel is 750 by default too, Xcode will be confused what to do and rightfully so! What you can do is set the content compression property in attributes inspector to 1000

                  如果您不想修改 抗压性(我以前觉得它们很吓人),您还可以添加一个 >= 约束到每个 UILabel 的宽度和高度.给出这个约束也可以显示完整的文本,无论它有多大,因为明确定义高度和宽度已经给了它们 1000 的优先级!

                  If you don't wish to tinker with compression resistance (I used to find them scary), what you can also do is add a >= constraint to the width and height both of each UILabel. Giving this constraint will also work to show the complete text no matter how large it be, as explicitly defining height and width has given them a priority of 1000!

                  这篇关于iOS - 将两个标签放在其超级视图的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UIImageView .scaleAspectFit 和自动布局无法从 Swift 以编程方式工作 下一篇:让 UITableViewCell 使用自动布局调整自身大小

                  相关文章

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

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

                    <legend id='pgnAw'><style id='pgnAw'><dir id='pgnAw'><q id='pgnAw'></q></dir></style></legend>
                      • <bdo id='pgnAw'></bdo><ul id='pgnAw'></ul>