Introduction to Lottie for Swift
\n\nLottie is a powerful open-source library developed by Airbnb that allows you to render vector animations created in Adobe After Effects on mobile and web platforms. Animations are exported in JSON format (using the Bodymovin plugin) and play in real time without loss of quality.
\n\nFor Swift developers, Lottie opens up endless possibilities: from simple loading indicators and icons to complex full-screen animations, welcome screens, and interactive interface elements. Unlike GIFs or videos, Lottie animations:
\n- \n
- Vector-based — scale without loss of quality on any device. \n
- Lightweight — JSON files typically weigh between 1 and 50 KB. \n
- Interactive — you can control playback, speed, color, and progress. \n
- Cross-platform — the same JSON works on iOS, Android, Web, React Native, and Flutter. \n
This article is a complete guide to using Lottie in Swift. You will learn how to install the library, master all key methods, explore a real example, and avoid common mistakes.
\n\nInstalling Lottie
\n\nLottie for Swift is installed via Swift Package Manager (SPM) or CocoaPods. The recommended method is SPM, as it is built into Xcode.
\n\nInstallation via Swift Package Manager (SPM)
\n- \n
- In Xcode, open your project and select File → Add Packages... \n
- Paste the repository URL:
https://github.com/airbnb/lottie-ios.git\n - Select the version (latest stable is recommended) and click Add Package. \n
- Ensure the package is added to your target. \n
Installation via CocoaPods
\nIf you use CocoaPods, add to your Podfile:
pod 'lottie-ios'\nThen run:
\npod install\n\nInstallation via Carthage (legacy method)
\ngithub "airbnb/lottie-ios"\nRun carthage update --platform iOS and add the framework to your project.
Important: After installation, import the library in the required file:
\nimport Lottie\n\nQuick Start with Code Example
\n\nLet's create a simple app that plays a Lottie animation full screen.
\n\nStep 1: Prepare the JSON file
\nDownload or create a Lottie animation. For testing, you can use free animations from LottieFiles. Place the JSON file (e.g., animation.json) in the Assets folder of your Xcode project.
Step 2: Write the code
\nimport UIKit\nimport Lottie\n\nclass ViewController: UIViewController {\n \n private var animationView: LottieAnimationView?\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // 1. Initialize animation from Assets\n animationView = LottieAnimationView(name: "animation")\n \n // 2. Set size and position\n animationView?.frame = view.bounds\n animationView?.contentMode = .scaleAspectFit\n \n // 3. Add to the screen\n view.addSubview(animationView!)\n \n // 4. Play the animation\n animationView?.play { (finished) in\n print("Animation finished: \\(finished)")\n }\n }\n}\n\nRun the app — you will see the animation play once. To make it loop infinitely, change the play call to play(fromProgress: 0, toProgress: 1, loopMode: .loop).
Key Lottie Methods and Functions
\n\nBelow are 10 key Lottie methods
Also in library
Prometheus Metrics in Rust: prometheus and metrics-exporter-prometheus Libraries
GraphQL in C# (.NET): Hot Chocolate and GraphQL.NET libraries for creating APIs
Node.js Monitoring: Tools and Libraries for Observability
Working with Images in C# (.NET): A Complete Guide
QR Code Generator in Rust: Creation and Integration into Web Applications