7

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

Jonathan Arbogast
  • 9,620
  • 4
  • 35
  • 47
carbonr
  • 6,049
  • 5
  • 46
  • 73
  • 1
    Animated GIF like image.gif won't animate with `iOS` SDK. – Buntylm Oct 19 '13 at 05: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 Oct 19 '13 at 06: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 Oct 19 '13 at 06:23

1 Answers1

8

Go to your Images.xcassets folder and create a folder named MyGifAnimation.xcassets, then put your MyGifAnimation@2x.gif 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": "MyGifAnimation@2x.gif"
    }],
    "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.

isair
  • 1,790
  • 15
  • 15
  • 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 Feb 15 '16 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 Feb 17 '16 at 01: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... – Nicolas Miari Feb 17 '16 at 01:47