iPhone how to get UITextField's text while typing?

后端 未结 7 2059
别那么骄傲
别那么骄傲 2020-12-12 21:54

I\'m trying to show changes made to a UITextField on a separate UILabel. Is there a way to capture full text of the UITextField after

7条回答
  •  清歌不尽
    2020-12-12 22:31

    Swift 3.0+: This worked very nicely for me.

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        self.yourLabel.text = "\(textField.text ?? "")\(string)"
        return true
    }
    

提交回复
热议问题