Search code examples
iosswift3uiimage

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.


Solution

  • 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