Question

I want to animate the change of a UILabel's title, even when the title's string is the same as the previous. My code:

[self.firstletterbutton setTitle:goodletter forState:UIControlStateNormal];
                [self.secondletterbutton setTitle:badletter1 forState:UIControlStateNormal];
                [self.thirdletterbutton setTitle:badletter3 forState:UIControlStateNormal];

If I change a UIButton title it's animated with a "flash". However if I change the title to the same string it doesn't animate. How can I force the animation?

Was it helpful?

Solution

Prior to iOS7 title did not have animations, but in iOS 7 it seems they have added the flash animation when it changes. One possibility might be to set the title blank first, and then to the same value again to simulate a change. If this causes unwanted blinking, you could also try to append some non-printing character to the title momentarily (finding a suitable one left as exercise to reader).

Or, you could try doing an altogether different transition, e.g., with something like:

[UIView transitionWithView:self.firstletterbutton duration:0.3 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
    [self.firstletterbutton setTitle:goodletter forState:UIControlStateNormal];
} completion:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top