Search code examples
iosswiftxcodeautolayout

Autolayout for FLAnimatedImageView in Swift


I'm using FLAnimatedImageView to integrate GIFs into my app using the GIPHY API. I had added autolayout constraints for leading, trailing, top, bottom, and height. However, for some reason, the image ends up being larger than my height constraint (image below). How should I fix this?

original

new


Solution

  • UIView has a contentMode property. FLAnimatedImageView inherits from UIImageView, which inherits from UIView so you can use contentMode in FLAnimatedImageView as well.

    Set contentMode to .scaleAspectFit and it should resize the image to fit the image view without modifying the aspect ratio.