How to resize UIImageView based on UIImage's size/ratio in Swift 3?

前端 未结 8 1535
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 19:01

I have a UIImageView and the user is able to download UIImages in various formats. The issue is that I need the UIImageView to resize

8条回答
  •  無奈伤痛
    2020-11-28 19:23

    Set your imageView to aspectFit, that will resize the image to not exceed your imageView's frame.

    You can get the size of your UIImage of your imageView with logic from this question - basically just get the height and width of the UIImage.

    Calculate the ratio and set the width/height of the imageView to fit you screen.

    There is also a similar question to your that you might get you answer from.

提交回复
热议问题