简体   繁体   English

UITableViewAutomaticDimension将具有自动布局约束的单元格内容切到底部

[英]UITableViewAutomaticDimension chopping contents of cell with auto layout constraints to bottom

an image is shown in one of the cells. 图像显示在其中一个单元格中。

The image's constraints are as follows: 图像的约束如下:

在此处输入图片说明

The height for this cell in heightForRow is set as UITableViewAutomaticDimension. heightForRow此单元格的高度设置为UITableViewAutomaticDimension。 But the image gets chopped off from the bottom. 但是图像从底部被切掉。 How to resolve this so that the image is shown fully? 如何解决此问题,以便完整显示图像? Thank you. 谢谢。

output is shown as below: 输出如下所示:

在此处输入图片说明

As i mentioned in the comment, if you want a self sizing cell, decide which element (or a combination) will determine the height. 正如我在评论中提到的,如果您想要一个自定义单元格,请确定哪个元素(或组合元素)将确定高度。 In your case the image view has a hight constraint, which means, create leading, top and bottom constraint with lower priority than the top one, otherwise IB will complain about the Y position. 在您的情况下,图像视图具有较高的约束,这意味着创建优先级,顶部和底部约束的优先级要低于顶部约束,否则IB将抱怨Y位置。 Then trailing to your label with >= 8 or something like that, then UILabel trailing to super view, and finally Y position for the label, either center in Y or give it a top, or bottom constraint, or both, but either lower priority than for image view or lower hugging priority. 然后使用>= 8或类似的符号尾随您的标签,然后UILabel尾随进入超级视图,最后是该标签的Y位置,位于Y的中心,或赋予其顶部或底部约束,或同时赋予两者,但优先级较低比图片视图或更小的拥抱优先级。

here are the constraints of the image view: 这是图像视图的约束:

在此处输入图片说明

The bottom constraint has lower priority than the top one. 底部约束的优先级低于顶部约束。 The UILabel is centered vertically, so it has no effect on cell size. UILabel垂直居中,因此对像元大小没有影响。 If you have top and bottom constraints for UIlabel, make sure their priority is lower than the ones of image view ones, or that its hugging priority is lower than image view. 如果您对UIlabel具有顶部和底部约束,请确保其优先级低于图像视图的优先级,或者确保其拥抱优先级低于图像视图。

Here is what it looks like in simulator: 这是模拟器中的外观:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM