How to do a live UITextField count while typing (Swift)?

后端 未结 10 1229
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 13:37

I would like to count the character when user keep typing in UITextField with swift.

Image of Field and Label:

10条回答
  •  长情又很酷
    2020-12-05 14:27

    UITextView count while typing in Swift:

    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
    
            let textCount = textView.text?.count ?? 0 + text.count - range.length
            self.textCountLabel.text  = "\(textCount)"
            return true
        }
    

提交回复
热议问题