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
I spent many hours on this, and I finally got a solution that worked for me (Swift 3):
constraintHeight
)Then, when I need to display the image, I simply write the following (sampled from answers above):
let ratio = image.size.width / image.size.height
let newHeight = myImageView.frame.width / ratio
constraintHeight.constant = newHeight
view.layoutIfNeeded()
Basically, this ensures that the image fills the UIImageView's width and forces the UIImageView's height to be equal to the image's height after it scaled