How to add GIF images to Asset Catalog in XCode5
Asked Answered
M

1

7

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

Mcminn answered 19/10, 2013 at 5:32 Comment(3)
Animated GIF like image.gif won't animate with iOS SDK.Golden
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 addedMcminn
@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 assumptionsMcminn
G
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.

Geibel answered 27/3, 2014 at 9:45 Comment(3)
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.Endocranium
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.Geibel
@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...Maclean

© 2022 - 2024 — McMap. All rights reserved.