美文网首页
【转载】UITextField - Create a textf

【转载】UITextField - Create a textf

作者: ChaichaiChai | 来源:发表于2016-02-22 11:46 被阅读13次

Show/Hide the keyboard while using the UITextView/UITextField
To show the keyboard:

self.inputTextView.becomeFirstResponder()

To hide the keyboard:

self.inputTextView.resignFirstResponder()

To hide the keyboard while tapping outside the UITextField/UITextField:

@IBOutlet weak var inputTextView: UITextView!

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        self.inputTextView.resignFirstResponder()
    }

To hide the keyboard while tapping the return key in the UITextField:

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var inputTextField: UITextField!
    
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.inputTextField.delegate = self

原文地址:http://studyswift.blogspot.com/2015/09/uitextfield-create-textfield.html

相关文章

网友评论

      本文标题:【转载】UITextField - Create a textf

      本文链接:https://www.haomeiwen.com/subject/ptlbkttx.html