Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove spacing from UIImageView aspect fit in Swift

I created a UIImageView and assigned it an UIImage. I set the UIImageView content mode to Aspect Fit. How do I remove the padding from the top and bottom of the image, or how do I resize the UIImageView to wrap around the image? I tried everything.

If you are going to say to get the new size of the image, it won't work. Getting the image size inside the UIImageView only gives the width and height of the original image.

Please do not link other posts. I have read them already. They do not work.

enter image description here

like image 418
Walter M Avatar asked Sep 10 '15 23:09

Walter M


1 Answers

You may calculate it manually for UIImageView's frame sizes that Aspect Fit with your image, or use AVMakeRectWithAspectRatioInsideRect(method from AVFoundation).

like image 87
MailE Avatar answered Oct 19 '22 20:10

MailE