Prevent Keyboard from appearing when tapping on UITextField

前端 未结 6 733
孤城傲影
孤城傲影 2021-01-19 22:11

I\'m using a UITextField to show results of a calculation but I don\'t want the keyboard to appear when the user taps on the UIText

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 22:45

    First set delegate with your UITextField in self class.

    You can do with below 2 ways.
    1. From storyboard
    2. From Code ( You can write at viewDidLoad() )

    textField.delegate = self

    Then declare protocol UITextFieldDelegate in your class.

    Now call delegate method.

    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        self.view.endEditing(true)
        return true
    }
    

提交回复
热议问题