swiftuiimageviewheightconstraintsaspect-fit

Swift image Aspect Fill for tall image not working


I have this UIImageView which may contain images with different ratios. I have studied the properties of UIImageView and it seems that the Aspect Fill property set for the Mode of the View should be what I need.

It works as intended when the image is wider than taller: cuts the left and right parts of the image out of the UIImageView.

However if the image is taller than wider it does not cut the above and below part of the image, it allows the image to come out of its view and overlap below views.

These are the constraints I have for the UIImageView: enter image description here

I have seen several tutorials proceeding like I do, but the result is different for me.


Solution

  • If the image is fitting correctly, but is extending outside the bounds of the image view, try turning on "clip subviews"