Change UITextField background when editing begins

后端 未结 4 1524
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 11:12

I\'d like to change the background image of a UITextField when it becomes the firstResponder to show the user that it has focus, similar to the :active or :focus pseudo-clas

4条回答
  •  再見小時候
    2020-12-29 11:35

    You can probably try observing for changes to isFirstResponder. and changing the background in the notification method. Something like:

    [textField addObserver:theObserver forKeyPath:@"isFirstResponder" options:0 context:nil];
    

    Then in the observer:

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        if(object == textField && [keyPath isEqual:@"isFirstResponder"]) {
            //fiddle with object here
        }
    }
    

提交回复
热议问题