How do I check when a UITextField changes?

后端 未结 19 3142
情话喂你
情话喂你 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条回答
  •  没有蜡笔的小新
    2020-11-22 16:25

    swift 4

    In viewDidLoad():

        //ADD BUTTON TO DISMISS KEYBOARD
    
        // Init a keyboard toolbar 
        let toolbar = UIView(frame: CGRect(x: 0, y: view.frame.size.height+44, width: view.frame.size.width, height: 44))
        toolbar.backgroundColor = UIColor.clear
    
        // Add done button
        let doneButt = UIButton(frame: CGRect(x: toolbar.frame.size.width - 60, y: 0, width: 44, height: 44))
        doneButt.setTitle("Done", for: .normal)
        doneButt.setTitleColor(MAIN_COLOR, for: .normal)
        doneButt.titleLabel?.font = UIFont(name: "Titillium-Semibold", size: 13)
        doneButt.addTarget(self, action: #selector(dismissKeyboard), for: .touchUpInside)
        toolbar.addSubview(doneButt)
    
        USDTextField.inputAccessoryView = toolbar
    

    Add this function:

        @objc func dismissKeyboard() {
          //Causes the view (or one of its embedded text fields) to resign the first responder status.
          view.endEditing(true)
        }
    

提交回复
热议问题