I've been struggling with fitting an UIImageView
which shows images of variable widths and heights with Aspect Fill
. The cell height is not adapting to the new height of the UIImageView
and persist it's height.
The hierarchy of the views is this
- UITableViewCell
- UITableViewCell.ContentView
- UIImageView
- UITableViewCell.ContentView
I tried these scenarios in XCode Auto Layout :
- set the
UIImageView => Height
toremove at build time
- set the
Intrinsic Value
of theUIImageView
toplaceholder
- set the
Intrinsic Value
for each of theUIImageView
,ContentView
andUITableViewCell
toplaceholder
With any of these combinations I get this view:
https://i.stack.imgur.com/Cw7hS.png
The blue lines represent the cell borders (boundaries) and the green ones represent the UIImageView
border (boundaries). There are four cells in this example, the 1st and the 3rd ones have no images and the 2nd and the 4th ones have the same image (overflowing over the ones which have none).