My UIImageView
is in aspect fit mode which leaves blank space beneath the actual image.
The blue space is what I want to eliminate so the imageView wraps the image (if only I had wrap content). Seemed like an easy task but I soon realized that the image is in aspect fit so the image view changes the width and height of the image but then I would have to make a calculation on the image view based on that altered image which would make a never ending loop of shrinking the image.
I just want to remove the blank space to make it look more concise. Full project at GitHub: https://github.com/sak6lab/Closet-Space
I filed a radar recently for this as I believe it is broken behaviour.
Currently, the best way I have found to fix this is to add an aspect ratio constraint to the image view based on the aspect ratio of the image. (You'll have to update the constraint when the image changes though).
Something like...
imageView.widthAnchor.constraint(equalTo: imageView.heightAnchor, multiplier: image.size.width / image.size.height).isActive = true
You could wrap this into a UIImageView
subclass maybe. Override the didSet
of the image
property or even just add a new function.
Be careful though as you need to make sure you only create one constraint and on subsequent passes you update the already existing constraint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With