-1
可能重复:
How to animate the background color of a UILabel?的UILabel更改背景颜色逐渐
哈雷,我有一个的UILabel用白色背景颜色,然后我有一个开关,当我打开一操作会将背景颜色更改为黑色。 有没有一种模式可以逐渐改变这种颜色?我不想立即改变颜色,但会产生关闭的效果。 谢谢。
可能重复:
How to animate the background color of a UILabel?的UILabel更改背景颜色逐渐
哈雷,我有一个的UILabel用白色背景颜色,然后我有一个开关,当我打开一操作会将背景颜色更改为黑色。 有没有一种模式可以逐渐改变这种颜色?我不想立即改变颜色,但会产生关闭的效果。 谢谢。
您可以使用Core Animation或UIView动画。
//viewDidLoad
//Initial Color of White
label.backgroundColor = [UIColor whiteColor];
//Animate to black color over period of two seconds (changeable)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2]; //Change the "2" to the desired duration
label.backgroundColor = [UIColor blackColor];
[UIView commitAnimations];
此代码不一定必须在viewDidLoad
。你可以把它放在任何你希望它被调用的地方,但是因为这是一个UIView动画,而不是一个核心动画动画,它不能和任何其他的UIView动画同时运行。
希望这会有所帮助!