Could you please tell me how to animate the textColor
of a UILabel?
For example I would like to change the color from WHITE to RED, then come back to WHITE with a fade-in effect and repeat that about 3 times.
I need this animation because my app gets real time data from the internet and when a value is changed I need to animate this text value to tell the user that it has changed.
Thank you so much.
I'm unsure if textColor is animatable on UILabel directly. But if you use a CATextLayer it will be much easier to get this effect,
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 is an old question but currently it's definitely possible to animate the text color with a CrossDissolve. Here's how to do it in Swift:
Try :)
Thanks to this answer - I achieved this with cross dissolve:
Usage:
The question was asked long ago, but here goes.
As said above, textColor for
UILabel
is not animate-able. A useful trick is to dynamically create in code anotherUILabel
, with the same attributes and position, but with a destination color. You animate the alpha of the newUILabel
from 0.0 to 1.0, so it appears like the textColor of the original UILabel is animated. You can remove one of the labels when the animation is completed.Here is an example of a class level method that changes to a different textColor for a short while and changes it back.