iosuiimageviewuiimagegifanimated

Load Animated gif in UIImageView IOS


I have this gif into my assets file Gif

The name of the assets is loading_apple but when I add the following code I get a nullpointer exception error:

let img = UIImage (named: "loading_apple")

So how can I show this gif ? :(

Hope someone can help me.


Solution

  • I would recommend breaking out the frames of that gif and use animatedImageNamed:duration: - you can name them all the similar name with a number change at the end. For instance:

    loading-1.png loading-2.png loading-3.png etc.

    Xcode will recognize you want multiple images and will play those through in order.

    Look at THIS