Disabling user input for UITextfield in swift

后端 未结 8 898
半阙折子戏
半阙折子戏 2021-02-01 11:55

pretty trivial question, I know. But I can not find anything online.

I need to disable the user from being able to edit the text inside of a text field. So that when the

8条回答
  •  独厮守ぢ
    2021-02-01 12:45

    Another solution, declare your controller as UITextFieldDelegate, implement this call-back:

    @IBOutlet weak var myTextField: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        myTextField.delegate = self
    }
    
    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
        if textField == myTextField {
            return false; //do not show keyboard nor cursor
        }
        return true
    }
    

提交回复
热议问题