Search code examples
iosuiimageviewios-autolayoutaspect-fit

How to get actual height of the image occupied in imageview for aspect fit


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 ?


Solution

  • for me :

    let image: UIImage = UIImage(named: "") 
    print(image.size) // 400x400 
    let scaleFator = UIScreen.main.scale //3 
    let height = image.size.height / scaleFator ///here the actual height of image.