I'm searching to limit the number of characters that an user can enter in a textfield.
I find this method and it's working very well
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let currentCharacterCount = textField.text?.characters.count ?? 0
if (range.length + range.location > currentCharacterCount){
return false
}
let newLength = currentCharacterCount + string.characters.count - range.length
return newLength <= 25
But now, I wanted to put different limits for 2 different textfields.
Does someone have a clue?
textFieldparameter to distinguish between different textviews if you want to use the same delegate for them. - A-Live