Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating UIButton text color

Is there a way to animate the textColor property of a UIButton? I've found some solutions for UILabel text color animation, but haven't seen any for UIButton.

like image 902
tresnotas Avatar asked Jul 15 '12 03:07

tresnotas


2 Answers

Use transition with view

[UIView transitionWithView:backButton
                          duration:0.5f
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^{
                            [backButton setTitleColor:[_peacock lighten:d.primary] forState:UIControlStateNormal];
                        }
                        completion:^(BOOL finished){
                        }];
like image 118
Johnny Rockex Avatar answered Sep 30 '22 20:09

Johnny Rockex


NSTimer is absolutely no good as an animation tool, nor should it be used for timekeeping in general where precision is needed (frame rate). This blog post perfectly exemplifies my position on what to do about non-animateable UILabel properties, which should be sent off to the render server through CA, not an NSTimer. Instead of UILabel, you can use or wrap CATextLayer and animate it's foregroundColor property in the standard animation block.

like image 28
CodaFi Avatar answered Sep 30 '22 20:09

CodaFi