0

How to create automatic table view cell size with complicated structure, which contains big amount of subview?

Here is an example of table view cell:Table view cell example

For example, total height of table view cell is 220 px: Brown area - 70 px, green area 90px, red - 10 px and black - 50px. Blue area always will be same height as tableview cell.

How can i decrease tableview cell height using autolayout and UITableViewAutomaticDimension to become 130px by removing/hiding/whatever that whole green area?

Is it possible to achieve it using UITableViewAutomaticDimension and correct constraints without any old style approach?

NOTE: Minimum version is iOS 8(but iOS 9+ solution will be ok too, i'll increase minimum version...)

Procurares
  • 2,169
  • 4
  • 22
  • 34
  • Just set the constraints ;) we cannot do that for you. If you then encounter specific questions feel free to ask. As is, the question is too broad. – HAS Oct 04 '16 at 17:38
  • "Is it possible to achieve it using UITableViewAutomaticDimension and correct constraints without any old style approach?" Yes it is. Do you understand how automatic cell height works? – matt Oct 04 '16 at 19:28

2 Answers2

1

I would suggest using a vertical UIStackView with everything else inside it. A stack view has the wonderful feature that it sets up the constraints of its contained views for you — and it compensates when you insert or remove a contained view, which seems to be what you're after. You could set up those constraints yourself each time you remove or insert a view, but your question implies that you don't know how to do that. A UIStackView does know how.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

Once you added the constraints, you can create an outlet to the height constraint thats attached to the green section and change it to be height = 0 (or whatever you want), then change the height of the entire cell.

Andrew Cook
  • 116
  • 1
  • 8