Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Can a gif be loaded from an asset catalog? #66

Closed
neilyoung opened this issue Nov 3, 2017 · 5 comments
Closed

Can a gif be loaded from an asset catalog? #66

neilyoung opened this issue Nov 3, 2017 · 5 comments

Comments

@neilyoung
Copy link

neilyoung commented Nov 3, 2017

Getting

SwiftGif: This image named "njoy" does not exist

while trying

@neilyoung neilyoung changed the title Can a gif loaded from an asset catalog? Can a gif be loaded from an asset catalog? Nov 3, 2017
@Aaron-Thomas
Copy link

Same thing happened to me. Xcode now doesn't recognise gif files in the .xcassets folder. To solve this i made a new group called 'Gif', outside of the .xcassets folder and added my .gif files to this. Then called it in the same way; e.g. myImageView.image = UIImage.gif(name: "mygif") Worked for me!

@xAlien95
Copy link

You could extend your UIImage class:

extension UIImage {
    public class func gif(asset: String) -> UIImage? {
        if let asset = NSDataAsset(name: asset) {
            return UIImage.gif(data: asset.data)
        }
        return nil
    }
}

You'll be able to load GIFs from assets based on their names using

imageView.image = UIImage.gif(asset: "njoy")

@bahlo
Copy link
Member

bahlo commented Feb 17, 2018

#68 is merged, closing. Feel free to open if the issue persists.

@bahlo bahlo closed this as completed Feb 17, 2018
@bitops
Copy link

bitops commented Jun 10, 2018

@bahlo I am using version 1.6.1 and encountered this error. I looked in the source code that CocoaPods pulled down and I don't see the code that allows you to look up the image as an asset. Is the code not released or am I doing something wrong? Thanks so much!

By putting my images in a folder outside of the asset folder I was able to load the image just fine.

@AdiAyyakad
Copy link

AdiAyyakad commented Aug 13, 2018

Seconded. Can a version please be released with this PR in it? Also just generally it looks like there have been quite a few changes added to SwiftGif without a release - is there any plan to release it soon @bahlo? Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

6 participants