I have an imageview inside a UITableViewCell.
Imageview with Aspect Fit creates a lot of extra space in the top and bottom if the image is large. The extra space (gray background color) is shown in the picture below.
How do I remove the extra space?
This particular image is 890 x 589 and the screenshot was taken on a iphone 6S simulator.
I am using UITableViewAutomaticDimension for automatic table cell height.
There is no height constraint on the imageview so it can resize accordingly.
Thank you in advance.
The above answer doesn't work when using UITableViewAutomaticDimension.
In general the problem is that in the tableView function "cellForRowAt indexPath" tableView hasn't yet laid out cell and it's subviews.
So one solution to this problem is using a subclass of UITableView:
Now you can use any of the solutions in for instance the link in Md Rais' comment. As an example my own code: