如何动画一个UILabel的文字颜色? [英] How to animate the textColor of a UILabel?

查看:205
本文介绍了如何动画一个UILabel的文字颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请你告诉我的如何动画文字颜色的一个UILabel

Could you please tell me how to animate the textColor of a UILabel?

例如我想的颜色从白色变成红色,然后再回到白色淡入效果,重复3倍左右。

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.

感谢您这么多。

推荐答案

之所以说文字颜色不能设置动画的是,使用的UILabel定期的CALayer而不是CATextLayer的。

The reason that textColor is not animatable is that UILabel uses a regular CALayer instead of a CATextLayer.

若要文字颜色动画(以及文本,字体等),我们可以继承的UILabel并使其使用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 :-)

您可以找到一个完整的解释+在这一个下拉的开源替代的UILabel <一个href=\"http://corecocoa.word$p$pss.com/2011/10/04/animatable-text-color-of-uilabel/#more-30\">article

You can find a complete explanation + a drop-in open source replacement for UILabel in this article

这篇关于如何动画一个UILabel的文字颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆