Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Swift How To Use Gif File Inside My Project

In my app I need to use .gif and I did searched on it. Everyone asked to use UIImage.gifImageWithName("funny") or UIImage.gifWithName("jeremy") for adding .gif file. But I'm getting error on those Type 'UIImage' has no member 'gifWithName'. How to solve those Issues and How to use .gif in my app.

like image 229
Kavin Kumar Arumugam Avatar asked May 09 '17 12:05

Kavin Kumar Arumugam


People also ask

How do I use a GIF file?

Just find a GIF that you want and press the “copy link” button. Then, paste the link where you want to use your GIF. On most sites, the GIF will work automatically. Use Gboard: The Google Keyboard for Android, iPhone, and iPad has a built-in GIF function that allows you to use GIFs anywhere, even in text messages.


2 Answers

Download UIImage+Gif.swift file from https://github.com/bahlo/SwiftGif/tree/master/SwiftGifCommon and put into your project..

// An animated UIImage
let Gif = UIImage.gif(name: "jerry")

// A UIImageView with async loading
let imageView = UIImageView()
imageView.loadGif(name: "tom")]

demo

like image 129
kartik patel Avatar answered Oct 16 '22 17:10

kartik patel


iOS won't support .gif images directly. You have to use latest version of third party library like SDWebImage. The simplified solution is to use Webview.

Or else, You can use UIImageView+Extension

like image 26
Sivajee Battina Avatar answered Oct 16 '22 16:10

Sivajee Battina