iOS – Add Tap Gesture to UITextField

2 Solutions Collect From Internet About “iOS – Add Tap Gesture to UITextField”

UITextField has delegate methods, you might want to consider implementing those. Or just add action event to your textfield.

For example in viewDidLoad

textField.addTarget(self, action:Selector("textDidBeginEditing"), forControlEvents: UIControlEvents.EditingDidBegin)

Then implement this:

func textDidBeginEditing(sender:UITextField) -> Void
   // handle begin editing event

If you set the textfields delegate, you can use;

optional func textFieldDidBeginEditing(_ textField: UITextField)


optional func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool