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

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

        让 UITableViewCell 使用自动布局调整自身大小

        时间:2023-09-09
      1. <tfoot id='uaJX6'></tfoot>

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

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

              <tbody id='uaJX6'></tbody>

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

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

                  问题描述

                  我在 UITableViewCell 中有 3 个标签,并设置了标签以便它们自动换行.如果他们自动换行,则文本将进入下一个单元格.如何让 AutoLayout 根据内容展开单元格,而无需在 heightForRowAtIndex 方法中编写代码?难道没有一个约束我可以用来根据 contentView 自动调整单元格吗?

                  I have 3 labels in a UITableViewCell and have the labels set so they will wordwrap. If they word wrap the text goes into the next cell. How do I get AutoLayout to expand the cell based on the content without having to write code in the heightForRowAtIndex method? Isn't there a constraint I can use to automatically adjust the cell based on the contentView?

                  如果文本不包含在标签中,则单元格看起来很好.一旦包裹起来,就是问题发生的时候,我想让单元格调整大小以适应内容,并且底部标签和底部之间的间距与顶部和顶部标签之间的间距相同.

                  The cell looks fine if the text doesn't wrap in the label. Once it wraps that is when the problem occurs and I would like to have the cell resize to fit the content and have the same spacing between the bottom label and the bottom as there is between the top and top label.

                  推荐答案

                  很遗憾,您不能这样做.表格视图首先计算自己的总高度,并且在加载时对每个单元格的大小有一个固定的概念,它不会从外向内确定它的高度,也不会让布局约束改变单元格的高度.

                  Unfortunately no, you can't do this. A table view calculates its own total height first and has a fixed idea of the size of each cell as they load, it won't determine it's height from the outside in and it won't let layout constraints change the height of a cell.

                  如果您考虑表格是如何工作的,以及单元格重用,那么如果不加载每个单元格并将其添加到滚动视图,并对整个事物执行布局传递,您就无法真正根据其单元格调整表格大小.这可能会导致性能很差.

                  If you think about how tables work, with cell reuse, then you couldn't really size the table from its cells without loading in every cell and adding it to the scrollview, and performing a layout pass on the whole thing. That would probably lead to quite poor performance.

                  您可以尝试填充空闲"单元格(即您刚刚实例化的单元格,未添加到表中)并在计算 heightForRow 时为数据源中的每一行布置它.

                  You could experiment with populating a "free" cell (i.e a cell you've just instantiated, not added to a table) and laying it out for each row in your datasource when calculating heightForRow.

                  这篇关于让 UITableViewCell 使用自动布局调整自身大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iOS - 将两个标签放在其超级视图的中心 下一篇:如果禁用滚动,您能否根据显示的行数来更新 UITableView 的内在内容大小?

                  相关文章

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

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

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