0

I have created a category on UITextField which allows to animate between red and white color as shown below:

@implementation UITextField (Additions)

-(void) flash
{
    [UIView animateWithDuration:2.0 animations:^{

        [self setBackgroundColor:[UIColor redColor]];

    } completion:^(BOOL finished) {

        [self setBackgroundColor:[UIColor whiteColor]];
    }];

}

@end

I call it like this:

[self.paymentTextField flash];

First time it works and it shows the red background and then switches back to white color. But on second call it does not do anything.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
john doe
  • 9,220
  • 23
  • 91
  • 167
  • Looks like it isn't as easy as it seems: http://stackoverflow.com/questions/3944416/ipad-animate-uilabels-color-changing You can work around by creating a red UIView on top of your text field and animating it's alpha. – basar Jul 11 '13 at 16:50

1 Answers1

1

I'm not sure why that doesn't work. I tried it and got the same thing. However, since the color doesn't really animate, you can do it like this instead:

self.backgroundColor = [UIColor redColor];
[self performSelector:@selector(setBackgroundColor:) withObject:[UIColor whiteColor] afterDelay:2];

This should give you the same look.

rdelmar
  • 103,982
  • 12
  • 207
  • 218