0

Prototype Cells

I am using the attached prototype cell layout in a tableview. Each cell is sized using autolayout:

tableView.rowHeight = UITableViewAutomaticDimension

The "tagline" is a string and sets the height of the cell depending on the length of the string. Given a greater length the height of the UIImageView also resizes. The ImageView is set to a variety to images with different sizes and aspect ratios. I would like to resize the image based on the beginning width of the ImageView(that does not change) and the resulting height and the image's aspect ratio.

The code to set the two is very straightforward.

cell.taglineLabel.text = tagline cell.recipeImageView.image = image

Inside a tableView cellForRowAt function I set the tagline first in the code, then the Image. However, if I attempt to resize the image and I inspect the bounds or frame size, the size is the original size. I am assuming the autosize is performing after the func. Therefore, I cannot determine size.

Is there a way to force the autosize after the tagline is set, so I can see the frame/bounds sizes I have to work with?

jz_
  • 338
  • 2
  • 14
  • It's difficult without more details on the constraints - maybe a concrete example might work. But have you tried setting a constraint (maybe with a different priority) that says the height of the image view *is* the height of the tagline label? –  May 23 '18 at 14:12
  • I have tried to be as detailed as possible. There really is little code here. 'cell.taglineLabel.text = recipe.tagline' 'cell.recipeImageView.image = image' but I added to the post. The two heights are adjust to be equal without a problem. The problem is I cannot determine what the height is to resize the image (not the UIImageView). – jz_ May 23 '18 at 14:20

0 Answers0