How do I check when a UITextField changes?

后端 未结 19 3147
情话喂你
情话喂你 2020-11-22 15:44

I am trying to check when a text field changes, equivalent too the function used for textView - textViewDidChange so far I have done this:

  fu         


        
19条回答
  •  Happy的楠姐
    2020-11-22 16:17

    Swift 4

    Conform to UITextFieldDelegate.

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        // figure out what the new string will be after the pending edit
        let updatedString = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
    
        // Do whatever you want here
    
    
        // Return true so that the change happens
        return true
    }
    

提交回复
热议问题