2009-02-25 17 views

答えて

4

背景色を切り替える機能を作成します。

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

} 

その後、セットアップタイマーは、この機能に

[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(flashBackground) userInfo: nil repeats: NO]; 
+0

感謝を呼び出します。ところで、それはredColorとwhiteColorです。私は複数の点滅のためにこれを拡張しました... NSTimerの反復でブール値のvarと点滅の数をカウンターで。 – 4thSpace

+0

@selectorメソッドflashBackgroundにパラメータを渡すにはどうすればよいですか?たとえば、UITextFieldオブジェクトを渡します。 – 4thSpace

+0

userInfoフィールドに渡すこともできますし、NSInvocationバージョンのscheduledTimerWithTimeIntervalを柔軟に使用することもできます。 –

関連する問題