How can I set the maximum amount of characters in a UITextField
on the iPhone SDK when I load up a UIView
?
This code is working fine when you are paste string more than your character limits.
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
let str = (textView.text + text)
if str.characters.count <= 10 {
return true
}
textView.text = str.substring(to: str.index(str.startIndex, offsetBy: 10))
return false
}
Thanks for your votes. :)