[Swift] TextView 글자 수 Count

김정윤·2023년 3월 29일
import UIKit

class ViewController: UITextViewDelegate {
    let maxLenghth = 200
    
    func textViewDidChange(_ textView: UITextView) {
        countLabel.text = "\(maxLength - textView.text.count)"
    }
    
    func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        return textView.text.count + (text.count - range.length) <= maxLength
    }
}

https://stackoverflow.com/a/35147599

profile
iOS앱개발자

0개의 댓글