Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the animation color in lottie in iOS?

Tags:

ios

swift

lottie

I am loading the animation typing indicator from the json file using lottie framework. I want to change the animation of the indicator color. I don't want to change the colour from the json file. Want to change the colour for animation view programmatically.

Eg : (. . . .) -> Typing indicator (Want to change the dot colour)

  private let animationView = LOTAnimationView(name: 
  Constants.ImageAssets.typingIndicatorIcon, bundle:Bundle(identifier: Constants.GenericKeys.bundleIdentifier)!)

    private func loadTypingIndicator() {
    animationView.loopAnimation = true
    animationView.translatesAutoresizingMaskIntoConstraints = true
    // *** It's not working 
    animationView.setValue(UIColor.green, forKeypath: "boule.Ellipse 1.Fill 1.Color", atFrame: 0)
    animationView.play()
}
like image 653
Devan Avatar asked Oct 09 '19 10:10

Devan


2 Answers

Maybe this helps:

let keypath = AnimationKeypath(keys: ["**", "Fill", "**", "Color"])
let colorProvider = ColorValueProvider(UIColor.green.lottieColorValue)
animationView.setValueProvider(colorProvider, keypath: keypath)
like image 183
G. Meira Avatar answered Oct 06 '22 10:10

G. Meira


Bumped into this question... in case anyone wanted to know more, here's a tutorial about using value provider to change the Lottie animation color. https://swiftsenpai.com/development/lottie-value-providers/

like image 41
Lee Kah Seng Avatar answered Oct 06 '22 09:10

Lee Kah Seng