7

Does any one know how to add GIF image files to an Asset Catalog in XCode5?

3
  • 1
    Animated GIF like image.gif won't animate with iOS SDK.
    – Buntylm
    Commented Oct 19, 2013 at 5:34
  • Showing the animated GIF, I'm handling in code. I'm basically migrating my old code to new version and moved all images to assets but a few gif's I have can't be added
    – carbonr
    Commented Oct 19, 2013 at 6:22
  • @XCodeMonkey this question is in not way a duplicate of the one you marked. I'm talking about the new feature added in XCODE 5 for managing assets. Please read before making assumptions
    – carbonr
    Commented Oct 19, 2013 at 6:23

1 Answer 1

8

Go to your Images.xcassets folder and create a folder named MyGifAnimation.xcassets, then put your [email protected] and MyGifAnimation.gif files in it. After that, create a Contents.json file. Open that with your favorite text editor and write the following in it:

{
    "images": [{
        "idiom": "universal",
        "scale": "1x",
        "filename": "MyGifAnimation.gif"
    }, {
        "idiom": "universal",
        "scale": "2x",
        "filename": "[email protected]"
    }],
    "info": {
        "version": 1,
        "author": "xcode"
    }
}

You'll have to handle the animation yourself as loading it directly to a UIImageView won't result in an animated gif.

3
  • 2
    Like @Joey, I could not get this to work in modern Xcode (7.2.1). The .xcassets editor displays the manually-created .imageset correctly, but calling imageNamed: on it returns nil.
    – aednichols
    Commented Feb 15, 2016 at 17:34
  • Thanks for letting me know guys, I'll check this issue and update my answer soon. This is a hacky way so I can understand it not working anymore.
    – isair
    Commented Feb 17, 2016 at 1:39
  • @BarışŞencan It doesn't look that hacky; can't check right now the exact details but it looks pretty much like the Contents.json files that Xcode typically generates... Commented Feb 17, 2016 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.