DelGiudice
DelGiudice

Reputation: 1877

How to adjust the height of a cell so the contents can fit on it?

I have this design, to set the image width to 100% i add 2 constrains trailing and leading space to superview to 0. Image mode is aspect fill. What do i need to do so the table view cell gets bigger?

As you can see the image is bigger than the row

Upvotes: 0

Views: 37

Answers (1)

LyricalPanda
LyricalPanda

Reputation: 1414

What you'll need to do is in your heightForRowAtIndexPath: method calculate how big the cell should be. Usually you'll have one or two different static numbers you're returning by default (i.e. 42 or 60). In your case, you need to determine what is being put in the cell, then calculate the height of what you're putting into the cell. You should be able to calculate the height of the cell based on the image dimensions and knowing you're using aspect fit.

Upvotes: 1

Related Questions