[ios] Animate text change in UILabel

I'm setting a new text value to a UILabel. Currently, the new text appears just fine. However, I'd like to add some animation when the new text appears. I'm wondering what I can do to animate the appearance of the new text.

This question is related to ios objective-c ipad uilabel caanimation

The answer is

I wonder if it works, and it works perfectly!


[UIView transitionWithView:self.label 

    self.label.text = rand() % 2 ? @"Nice nice!" : @"Well done!";

  } completion:nil];

Swift 3, 4, 5

UIView.transition(with: label,
              duration: 0.25,
               options: .transitionCrossDissolve,
            animations: { [weak self] in
                self?.label.text = (arc4random()() % 2 == 0) ? "One" : "Two"
         }, completion: nil)

Similar questions with ios tag:

Similar questions with objective-c tag:

Similar questions with ipad tag:

Similar questions with uilabel tag:

Similar questions with caanimation tag: