How to add GIF images to Assets folder and load them in UIImageView programmatically
According to your comment, this is the solution that you are searching:
make an extension of UIImage which uses SwiftGif:
extension UIImage { public class func gif(asset: String) -> UIImage? { if let asset = NSDataAsset(name: asset) { return UIImage.gif(data: asset.data) } return nil } }
Then tuning @Ganesh suggestion with the extension you might do something like:
imageView.image = UIImage.gif(asset: "YOUR_GIF_NAME_FROM_ASSET")
To load gif into UIImage I suggest two libraries
1) you can use this library
simply you can load it into UIImageView
let imageData = try! Data(contentsOf: Bundle.main.url(forResource: "logo-animation", withExtension: "gif")!)
let gifImage = UIImage.gif(data: data!)
imageView.image = gifImage
2) Or you can use this library
import FLAnimatedImage
then add outlet
@IBOutlet weak var fashImage: FLAnimatedImageView!
then use this code
let imageData = try! Data(contentsOf: Bundle.main.url(forResource: "logo-animation", withExtension: "gif")!)
fashImage.animatedImage = FLAnimatedImage(animatedGIFData: imageData)
Hope this will help you