I'm trying to making a kind of color pulse effect animating background color of a UIButton
to make it change continously from a color (WhiteColor) to another one (RedColor).
I'm trying to use CABasicAnimation
for changing Opacity but I can't make it work with color too.
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration=1.0;
theAnimation.repeatCount=HUGE_VALF;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
theAnimation.toValue=[NSNumber numberWithFloat:0.0];
[BigButton.layer addAnimation:theAnimation forKey:@"animateOpacity"];
Every suggestion would be appreciated. Thanks
I found the right way. You need to remember about CGColor. This was my mistake. Compiler didn't help here.
Objective C
Swift
I finally found out solution: I made a two frames animation in which I first change background color to Red and in the second frame I turn it white. I can also manipulate relative durations
Swift 4 - Animate any change on a button (
backgroundColor
,title
,titleColor
):