Created
February 17, 2018 10:25
-
-
Save darhonbek/a2f769e9a41c3b0827baa55143532e9a to your computer and use it in GitHub Desktop.
Ensure # of chars dose not exceed the limit (UITextField)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | |
let nsString = textField.text as NSString? | |
let newString = nsString?.replacingCharacters(in: range, with: string) | |
if let string = newString, | |
string.count > YOUR_LIMIT_HERE { | |
return false | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment