0

I would like to make the text in my UILabel called coloursLabel change text colour by itself. I have tried the following method as another SO answer suggested (albeit for the backgroundColor) but it still doesn't change. Am I missing something silly?

UILabel *coloursLabel = [[UILabel alloc] init];
    coloursLabel.text = @"This sentence is colourful!";
    [coloursLabel sizeToFit];
    coloursLabel.center = self.view.center;
    coloursLabel.frame = CGRectOffset(coloursLabel.frame, timeForPage(6), 0);

[UIView animateWithDuration:2.0 animations:^{
    coloursLabel.textColor = [UIColor greenColor];
    coloursLabel.textColor = [UIColor redColor];
    coloursLabel.textColor = [UIColor blueColor];
    coloursLabel.textColor = [UIColor yellowColor];
    coloursLabel.textColor = [UIColor blackColor];
} completion:NULL];

coloursLabel shows the correct text but the text is in black.

Any help would be much appreciated!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
WunDaii
  • 2,322
  • 4
  • 18
  • 26
  • 1
    possible duplicate of http://stackoverflow.com/questions/2426614/how-to-animate-the-textcolor-property-of-an-uilabel – limon May 28 '14 at 16:06

1 Answers1

0

UILabel's textColor is not animatable. You could write your own Label class, using a CATextLayer as mask and animate its layer's backgroundColor.

robert
  • 2,822
  • 1
  • 16
  • 19