【转载】UITextField - Create a textf

2016-02-22  本文已影响13人  ChaichaiChai

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

上一篇 下一篇

猜你喜欢

热点阅读