AutoLayout: variable height UITableViewCell containing stacked UILabel and UIImageView

I try without success to create UITableViewCell(in code, without an interface constructor) where the height of the cells expands to fit its contents. Content, a UILabel, which itself expands to fit the text. And UIImageView, which should also expand so that it is complemented by an image (maintaining the aspect ratio). Thus, a panoramic image can lead to a short height, and a portrait image will make the image much higher. The image is loading, so we may not know the dimensions first.

Even if I set a limit to capture the image representation in aspect 4: 3, which led to a fixed image, the cell limit seems to have a height of zero, so the label is on top of the image, the Image overlays the cells above and below. To make it work, in my example, I just use a static image resource and not load the image.

I use VFL for cellView containers:

V:|-[image]-[label]-|

What could be the reason that the image height is treated as zero / ignored?

enter image description here

+4
source share

All Articles