0

The majority of tutorials I've seen have illustrated the implementation of flexible table view cells with the usage of a UILabel. I want to achieve the same sort of functionality but instead have a subclass of a UIView with flexible height. So I would like this green region to be flexible, so I can place a custom view on the green view. What is the best way to do this, if any?

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Coach
  • 309
  • 1
  • 4
  • 14
  • Possible duplicate of [Using Auto Layout in UITableView for dynamic cell layouts & variable row heights](http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights) – Alex Kosyakov May 20 '16 at 21:38

1 Answers1

1

The takeaway points with Auto Layout dynamic height table view cells are:

  1. Your cell content have constraints that push outwards to define the cell size. This means that you need to setup constraints that unambiguously define the cell's height.
  2. You must set your table view's estimatedRowHeight to a value, e.g. 100.
  3. You must set your table view's rowHeight to UITableViewAutomaticDimension.

In your case, the constraints you need are:

  1. Image view leading constraint to superview
  2. Image view top constraint to superview
  3. Title label leading constraint to image view
  4. Title label top constraint to super view
  5. Title label trailing constraint to superview
  6. Green view leading constraint to superview
  7. Green view trailing constraint to superview
  8. Green view top constraint to title label
  9. Green view bottom constraint to superview
  10. Image view width constraint
  11. Image view height constraint
  12. And, of course, some views in your green view that define its height
paulvs
  • 11,963
  • 3
  • 41
  • 66