Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when UITextField's inputview opened?

I have set a custom UIDatePicker to UITextField. I can detect when it closes, because I have "Done" button in there. How can I detect when it's opened? I want to make screen darker while user is selecting.

like image 511
Gintas_ Avatar asked Sep 17 '25 15:09

Gintas_


1 Answers

This relies on the UITextFieldDelegate to determine when the textfield becomes active. The key to this working in your situation is to check the inputView of your textField to see if it matches the pickerView you are using. Ideally, the only change you will need to make is to replace the name of the pickerView variable I used.

func textFieldDidBeginEditing(textField: UITextField) {
    if textField.inputView == pickerView {
        // Do your thing here
    }
}
like image 170
CodeBender Avatar answered Sep 20 '25 07:09

CodeBender