Swift

学习笔记:swift——收回textfield键盘

2015-12-09  本文已影响2041人  独居焚香

首先,引用UITextFieldDelegate类

override func viewDidLoad() {
        super.viewDidLoad()
text.delegate = self
}

//点击return 收回键盘
   func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
//点击其他地方  收回键盘
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        text.resignFirstResponder()
    }

上一篇 下一篇

猜你喜欢

热点阅读