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?
Asked
Active
Viewed 200 times
0
-
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 Answers
1
The takeaway points with Auto Layout dynamic height table view cells are:
- 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.
- You must set your table view's
estimatedRowHeight
to a value, e.g.100
. - You must set your table view's
rowHeight
toUITableViewAutomaticDimension
.
In your case, the constraints you need are:
- Image view leading constraint to superview
- Image view top constraint to superview
- Title label leading constraint to image view
- Title label top constraint to super view
- Title label trailing constraint to superview
- Green view leading constraint to superview
- Green view trailing constraint to superview
- Green view top constraint to title label
- Green view bottom constraint to superview
- Image view width constraint
- Image view height constraint
- And, of course, some views in your green view that define its height

paulvs
- 11,963
- 3
- 41
- 66