其他分享
首页 > 其他分享> > swift UITextField 关闭键盘

swift UITextField 关闭键盘

作者:互联网

一、引用UIText Field Delegate代理

class TestController: UIViewController, UITextFieldDelegate {

二、设置软件盘可返回

//MARK: - 隐藏键盘 , UITextFieldDelegate
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    self.view?.endEditing(false)
    return true
}

三、设置相关 UITextField

// MARK: - viewDidLoad
override func viewDidLoad() {
    super.viewDidLoad()
    self.etData.delegate = self
}

四、完整代码

class TestController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var etData: UITextField!

    @IBOutlet weak var etDataTwo: UITextField!

    // MARK: - viewDidLoad
    override func viewDidLoad() {
        super.viewDidLoad()
        self.etData.delegate = self
        self.etDataTwo.delegate = self
    }

    //MARK: - 隐藏键盘 , UITextFieldDelegate
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        self.view?.endEditing(false)
        return true
    }
}

标签:self,MARK,键盘,viewDidLoad,func,UITextField,UITextFieldDelegate,swift
来源: https://blog.csdn.net/weixin_41454168/article/details/122594918