Animate UIButton's title change

Rudolf Adamkovič picture Rudolf Adamkovič · Nov 5, 2012 · Viewed 17.8k times · Source

Here I found how to animate UIButton's title change using now-deprecated beginAnimations:context: method:

UIBUtton title animation for iPhone

How to do the same thing using current APIs?

Update:

I've tried to use block-based animations:

NSTimeInterval animationDuration = animated ? 1.f : 0.f;
[UIView animateWithDuration:animationDuration delay:0.f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{
    [button setTitle:newTitle forState:UIControlStateNormal];
    [button setTitleColor:newTitleColor forState:UIControlStateNormal];
} completion:nil];

The color change is not animated.

Answer

jjv360 picture jjv360 · Nov 5, 2012

Use blocks:

[UIView transitionWithView:self.flipLabelButton duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{

    [self.flipLabelButton setTitle:newText forState:UIControlStateNormal];

} completion:nil];