views:

730

answers:

1

How can I make the background color of a UITextField blink?

+2  A: 

Create a function that toggles the the background color.

-(void) flashBackground
{
  UIColor* color = _flashOn ? [UIColor colorRed] : [UIColor colorWhite];
  _textField.backgroundColor = color;
  [_textField setNeedsDisplay];
  _flashOn = !_flashOn;

}

Then setup a timer to call this function

[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(flashBackground) userInfo: nil repeats: NO];
Andrew Grant
Thanks. BTW, it's redColor and whiteColor. I've extended on this for multiple flashes...with a boolean var on repeats in NSTimer and counter for number of flashes.
4thSpace
How to I pass a parameter to the @selector method, flashBackground? For example, passing in a UITextField object.
4thSpace
You could pass it in the userInfo field, or for more flexibility use the NSInvocation version of scheduledTimerWithTimeInterval.
Andrew Grant