How to disable UITextField editing but still accept touch?

后端 未结 15 2332
误落风尘
误落风尘 2020-11-29 19:55

I\'m making a UITextField that has a UIPickerView as inputView. Its all good, except that I can edit by copy, paste, cut and select te

15条回答
  •  长情又很酷
    2020-11-29 20:16

    In swift 3+ :

    class MyViewController: UIViewController, UITextFieldDelegate {
    
       override func viewDidLoad() {
          self.myTextField.delegate     = self
       }
    
       func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
          if textField == myTextField {
             // code which you want to execute when the user touch myTextField
          }
          return false
       }
    }
    

提交回复
热议问题