-1

可能重复:
如何为 UILabel 的背景颜色设置动画?

哈莉,我有一个背景颜色为白色的 UILabel,然后我有一个开关,当我打开一个动作时,背景颜色变为黑色。有没有一种模式可以逐渐改变这种颜色?我不想立即更改颜色,而是创建关闭效果。谢谢。

4

1 回答 1

1

您可以使用 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 动画同时运行。

希望这可以帮助!

于 2012-06-14T04:13:33.753 回答