-1

Possible Duplicate:
How to animate the background color of a UILabel?

Halle, I've an UILabel with a white background color, then I have a switch and when I switch on an action changes the background color to black. Is there a mode to change gradually this color? I don't want change immediately the color but create an effect of switching off. Thanks.

Community
  • 1
  • 1
Kerberos
  • 4,036
  • 3
  • 36
  • 55

1 Answers1

1

You can use Core Animation or UIView animation.

//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];

This code doesn't necessarily have to be in viewDidLoad. You could put it anywhere you want it to be called, but since this is a UIView animation and not a Core Animation animation, it cannot run at the same time as any other UIView animation.

Hope this helps!

pasawaya
  • 11,515
  • 7
  • 53
  • 92