Evan Pon Evan Pon - 9 months ago 71
iOS Question

Can you use springs & struts to adjust TableViewCell size for different devices?

I'm building a simple interface that contains a TableView (XCode 8, iOS 10). Most of the interface was simple to design with springs and struts. However, I don't see a way to set the springs for the TableViewCell, or it's ContentView. Consequently, when I size the device to larger sizes like an iPad, the rows stay the same height, at 44 points.

I'm not dealing with any dynamic content here, and it's fine for all the rows to be the same height. I'm just looking for a quick and easy way to have the row height adjust for the different devices so they look more proportional.

The TableCell contains a couple labels that have a larger font size specified for larger devices (wR hR) if that matters. The labels are set to spring in both vertical and horizontal directions, but are currently only changing horizontally.

Is there a way to do this using springs and struts, or do I need to switch it over to auto layout?


Answer Source

I think you should either use UITableViewAutomaticDimension for cell height and autolayout or, since you're ok with the same size for each cell, you can use heightForRowAt function and return something like return self.view.frame.size.height / 6