Rudolf Adamkovic Rudolf Adamkovic - 1 year ago 88
iOS Question

Animate UIButton's title change

Here I found how to animate

's title change using now-deprecated

UIBUtton title animation for iPhone

How to do the same thing using current APIs?


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 Source

Use blocks:

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

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

} completion:nil];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download