Reputation: 9660
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.
Upvotes: 0
Views: 114
Reputation: 104082
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.
Upvotes: 1