Swift image Aspect Fill for tall image not working

1.1k Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

For such condition , Two possible solution may help :

  1. Calculate aspect ratio based on your required dimension so that picture quality remains intact . ( ** use Aspect Fit calculator to find required ratio)

  2. CENTER OR ASPECT FIT attributs of Imageview

Thanks