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()
}
Maybe this helps:
let keypath = AnimationKeypath(keys: ["**", "Fill", "**", "Color"])
let colorProvider = ColorValueProvider(UIColor.green.lottieColorValue)
animationView.setValueProvider(colorProvider, keypath: keypath)
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With