Prevent Keyboard from appearing when tapping on UITextField

前端 未结 6 734
孤城傲影
孤城傲影 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:44

    you could use an "empty" inputview like this:

    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
        let inputView = UIView(frame: .zero)
        inputView.backgroundColor = UIColor.clearColor()
        inputView.opaque = false
        textField.inputView = inputView
    
        return true
    }
    

提交回复
热议问题