Luis Ramirez
Luis Ramirez

Reputation: 1624

UITableViewAutomaticDimension with auto layout

okay I am having trouble creating dynamic cells with tableview. My image collapse and looks like this. It works fine when the description is long but not when it is to short.

Image constraints are: width = 120, height = 160, top = 8, leading = 12.

Title constraints are: top = 8, leading to imageView = 8, trailing = 12.

Description constraints are: top to titleLabel = 5, leading to imageView = 8, trailing = 12, bottom = 12 enter image description here

Now instead of adding the bottom constraint to the description, I added it to the image and then the cell looks something like this. enter image description here Now the description is out of place and in the middle, where the it should be right under the title label.

Would really appreciate the help.

Upvotes: 1

Views: 394

Answers (1)

Prashant Tukadiya
Prashant Tukadiya

Reputation: 16446

You need to do a little change to fix this

  • Give Bottom of your UIImageView with >= relation with 12 constant value (750 Priority)

  • Give Bottom of your Desc label with >= relation with 12 constant value (With That your label text will stick on top ))

So Now the Autolayout Engine has two things to follow

  1. If your Label text is small then UIImageView will be consider as height

  2. If your Label text is larger then it will be used as Cell height

Hope is is helpful

Upvotes: 4

Related Questions