views:

59

answers:

1

Hello stackoverflow,

I am trying to animate backgroundColor property of UILabel class and being unsuccessful so far. Here the snippet of my code

-(void) blink {
  UIColor* originalColor = lblDescription.backgroundColor;
  lblDescription.backgroundColor = [UIColor yellowColor];

  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:1.0];
  lblDescription.backgroundColor = originalColor;
  [UIView commitAnimations];
}
//this code works if lblDescription is UIView and does not if UILabel

I found some claims that some UILabel properties are not animatable, but I couldn't substantiate that claim by reading Apple docs. I was wondering if someone can shed light on this problem.

+3  A: 

On this page from the View Programming Guide For iOS, "Table 1-2 Animatable properties" supposedly lists all the animatable properties of UIViews. It doesn't include backgroundColor.

But on the UIView Class Reference, under the backgroundColor property it says:

Discussion
Changes to this property can be animated. The default is nil.

So it's not clear why the UILabel's backgroundColor does not animate.

The workaround I've used in the past is to use a CATextLayer instead of a UILabel.

aBitObvious
Won't work in 3.1.3
bioffe
Try these two other workarounds in [this question](http://stackoverflow.com/questions/2426614/how-to-animate-the-textcolor-property-of-an-uilabel). Those should work in earlier OS versions.
aBitObvious