I would like to change the height of imageview based on how much height the image occupies in imageview.
I am using content mode Aspect Fit
Any ideas on how to do that ?
I would like to change the height of imageview based on how much height the image occupies in imageview.
I am using content mode Aspect Fit
Any ideas on how to do that ?
If you want your image to fill your whole image view and have limit only for width of that image view, then the following code should help:
let imageView: UIImageView = ...
let image: UIImage = ...
let imageSize = image.size
let scaleFactor = imageSize.height / imageSize.width
let imageViewHeight = imageView.bounds.width * scaleFactor
If you use constraint based layout you don't even need the imageViewHeight - you can use calculated scaleFactor to set corresponding constraint for height of the imageView
for me :