How to mimic 2 different row heights for a UItableview in universal storyboards based on size class?

366 Views Asked by At

I have a UITableview with a custom cell, using universal/unified storyboards. For the iPad, I would like the row height to be 120, and be 70 for all other size classes.

I don't see a direct way to change the row height in storyboard based on size classes (only 1 row height for all size classes).

The main reason I want to do this is to accommodate a bigger UIImageView for the ipad class size.

For any height any width size class: UIImageView height is 60, pinned to the top and bottom at 5 each.

For regular height and regular width size class: UIImageIvew height is 100, pinned to the top and bottom at 10 each.

Since I can only do 1 row height, adding these contraints based on size class causes warnings/errors, because these constraints are incompatible with only 1 row height.

How would I make this work with the limitation of only 1 row height for differing size classes?

1

There are 1 best solutions below

8
On

In iOS 8:

  • When you set top and bottom (and other) constraints on the things inside a cell, you size the cell's height automatically from the inside out. The constraints cause the cell to adopt the height needed to accommodate those constraints.

  • Constraints can be conditional based on size class; that is what the size class widget at the bottom of the canvas is for. You design the general case under w:Any h:Any, and switch to any special case and change the constraints for just that case.

So, putting those two things together, you can certainly design constraints for two different sets of size classes so as to determine the height of the cell differently.