Aspect ratio in UIImageView

2020-02-26 06:25发布

问题:

I got app which can add photo from camera or gallery. After adding each photo showes in UIImageView. But they show with bad aspect ratio. Photoes are extended on UIImageView's size.

How can i show photoes with their real aspect ration?

UPD and what about small pictures? if user will add really small picture, this picture will resize on all area of UIImageView. How show this pictures in real size?

回答1:

Doing myImageView.contentMode = UIViewContentModeScaleAspectFit; is one option.

But it isn't enough because it changes the aspect ratio of the image, but it doesn't change the source image.

The only way to do that is to use the UIGraphicsImageContext as explained there: Resize UIImage with aspect ratio?