Kingfisher icon indicating copy to clipboard operation
Kingfisher copied to clipboard

How to set GIF image using Data Type?

Open devny opened this issue 5 years ago • 3 comments

Hi. I would like to create a GIF image using a data type. However, using a kingfisher seems to be able to create images only with URLs. Is there a way?

devny avatar Mar 13 '19 08:03 devny

You could use an ImageDataProvider. More specifically, a RawImageDataProvider should be fine.

onevcat avatar Mar 15 '19 12:03 onevcat

Please give me some examples..

devny avatar Mar 18 '19 02:03 devny

I just needed answers for this case too so i am posting this if someone needs an example in the future :) :

if let bundleURL = Bundle.main.url(forResource: "the-name-of-your-gif", withExtension: "gif"), let data = try? Data(contentsOf: bundleURL) {
    let provider = RawImageDataProvider(data: data, cacheKey: "key-for-your-cache")
    imageView.kf.setImage(with: provider)
}

And your GIF file should be outside your Assets if you use the above code.

ibeleliev avatar Oct 28 '19 15:10 ibeleliev