I have a label which pops up displaying points in my application. I am using the following code to make the label get larger in scale, then smaller. I would also like to animate the color changing from purple to green. Can someone point me to a resource in achieving this?
mLabel.textColor = [UIColor purpleColor];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
mLabel.transform = CGAffineTransformMakeScale(1.5,1.5);
[UIView setAnimationRepeatCount:1];
mLabel.transform = CGAffineTransformMakeScale(0.5,0.5);
mLabel.textColor = [UIColor greenColor];
[UIView commitAnimations];
If you need to use IB colors that are specified for highlighted or selected states and want to animate the color change with fade out effect you can use next code:
Swift:
}
Try This:
Unfortunately, the color doesn't animate with UIView animations. The answers to this question give some good workarounds without using Core Animation.
If you don't mind using a CATextLayer instead of a UILabel, then the color (and the scaling in your example) can be animated like this:
You can use iOS 4.0's view transition method to do this:
The reason that textColor is not animatable is that UILabel uses a regular CALayer instead of a CATextLayer.
To make textColor animatable (as well as text, font, etc.) we can subclass UILabel and make it use a CATextLayer.
This is quite a lot of work, but luckily I already did it :-)
You can find a complete explanation + a drop-in open source replacement for UILabel in this article
This line of code works for me. Make sure to set the Options to Cross Dissolve Swift: