Add Lottie animated icons to your iOS or iPadOS app using Swift Package Manager and LottieAnimationView.
In Xcode, go to your project settings → Package Dependencies and add the Lottie package.
Import Lottie, create a LottieAnimationView with the name of your downloaded icon file (without the .json extension), and add it to the view.
import Lottie
class ViewController: UIViewController {
var animationView: LottieAnimationView!
override func viewDidLoad() {
super.viewDidLoad()
animationView = LottieAnimationView(name: "your_animation")
animationView.frame = CGRect(x: 0, y: 0, width: 150, height: 150)
animationView.center = view.center
animationView.loopMode = .loop
animationView.play()
view.addSubview(animationView)
}
}Use the animation view instance to control playback at runtime.
animationView.play()
animationView.pause()
animationView.stop()
animationView.loopMode = .playOnce