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

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

    1. <legend id='fTH4E'><style id='fTH4E'><dir id='fTH4E'><q id='fTH4E'></q></dir></style></legend>
          <bdo id='fTH4E'></bdo><ul id='fTH4E'></ul>

        指定视图大小何时取决于多个子视图的约束

        时间:2023-09-09
        <legend id='96GbB'><style id='96GbB'><dir id='96GbB'><q id='96GbB'></q></dir></style></legend>

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

              <small id='96GbB'></small><noframes id='96GbB'>

              • <bdo id='96GbB'></bdo><ul id='96GbB'></ul>

                1. <tfoot id='96GbB'></tfoot>

                  本文介绍了指定视图大小何时取决于多个子视图的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 UITableView 中使用自定义单元格.单元格中有 4 个视图.3 个 UILabel 和 1 个 UIImageView(灰色一个),如下图所示.标签的文本是动态的,因此宽度和高度是动态的.

                  I am using custom cell in UITableView. There are 4 views in cell. 3 UILabels and 1 UIImageView (grey colored one) as shown below. Text of labels are dynamic so width and height is dynamic.

                  这里 UIImageView 的宽度取决于 2 个标签.所以问题是指定标签和 UIImageView 之间的约束,这将决定 UIImageView 的宽度.

                  Here width of UIImageView depends on 2 labels. So issue is to specify constraints between labels and UIImageView that will decide the width of UIImageView.

                  看看下面如果第一个标签的文本很长会发生什么.

                  See below what happens if first label's text is long.

                  当宽度取决于多个标签的宽度时如何指定约束?

                  How to specify constraints when width depends on width of multiple labels?

                  更新:我尝试将标签的行数设置为 0,将固有大小设置为占位符.它也不起作用.下面是它的外观.我尝试将固有宽度和高度设置为无,但是当我为两个标签都这样做时会出错,如果只为一个标签设置则不会出错.

                  Update : I tried setting number of lines for labels to 0 and intrinsic size to placeholder. It's not working, too. Below is how it looks. I tried setting intrinsic width and height to none, but it gives error when I do that for both label, not giving error if set that for only one label.

                  更新:我更改了属性,下面显示了它们现在是什么以及单元格的显示方式.

                  Update : I changed properties and below is displayed what are they now and how the cell is displayed.

                  单元格:

                  第一行标签的约束(粉红色):

                  第二行标签的约束(青色):

                  推荐答案

                  我在尝试了很多东西后解决了这个问题.我唯一要做的就是将水平和垂直内容压缩阻力优先级设置为必需.即1000.我对所有标签都这样做了,因为我不希望任何标签修剪它们的内容.

                  I solved this after experimenting with lot of things. The only thing I had to do is to set horizontal and vertical content compression resistance priority to required.i.e. 1000. I did this for all labels because I don't want any of the labels to trim their content.

                  另外一件非常重要的事情是获得正确的单元格高度.如果在计算自定义单元格的高度时甚至出现 1pt 的错误,它将不会按预期显示.

                  One more thing which is too much important is Getting Right Height Of Cell. If there is even 1pt of error in calculating custom cell's height it will not be displayed as expected.

                  提示:

                  1. 如果任何视图的高度大于预期,则计算出的单元格高度可能大于实际需要的高度.
                  2. 如果任何视图垂直缩小或不显示全部内容,则计算出的单元格高度可能小于实际需要的高度.

                  Yoy 可以通过向您为单元格计算的高度(变量)添加/删除常数值来测试高度是否错误.

                  Yoy can test if height is wrong by adding/removing constant value to height (variable) you calculate for cell.

                  这篇关于指定视图大小何时取决于多个子视图的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:dequeueReusableCell 打破了cliptobounds 下一篇:UITableViewCell 子类布局在禁用自动布局的故事板中搞砸了

                  相关文章

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

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