iOS - Add Tap Gesture to UITextField

一笑奈何 提交于 2019-12-04 11:31:08

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)

or

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

etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!