How to Animate UILabel Properties

UILabel properties cannot be easy animated due to some various reasons, so code like this will have no effect on it:

1
2
3
4
5
6
7
self.someLabel.textColor = [UIColor blueColor];

[UIView animateWithDuration:0.3
                  animation:^{
  
                      self.someLabel.textColor = [UIColor redColor];
                  }];

But there is a simple solution. Instead of animating property we will perform transition on object itself.

Using transitionWithView should solve our problem:

1
2
3
4
5
6
7
8
9
10
self.someLabel.textColor = [UIColor blueColor];

[UIView transitionWithView:self.someLabel
                  duration:0.3
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{

                      self.someLabel.textColor = [UIColor redColor];

                } completion:nil];

This creates nice fade in/out animation which is exactly what we want.