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
2009-02-25 23:44:55
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
2009-02-26 05:18:20
How to I pass a parameter to the @selector method, flashBackground? For example, passing in a UITextField object.
4thSpace
2009-02-27 07:06:35
You could pass it in the userInfo field, or for more flexibility use the NSInvocation version of scheduledTimerWithTimeInterval.
Andrew Grant
2009-02-27 18:07:12