IOS UITextField limits the number of input words, iosuitextfield
The text box on iOS sometimes requires a limit on the number of words, such as the mobile phone number. The UITextField proxy simply writes a judgment. When the number of words exceeds the limit, you cannot delete the text box if you want to delete it, it can be written as a proxy to solve the problem.
-(BOOL) textField :( UITextField *) textField shouldChangeCharactersInRange :( nsange) range replacementString :( NSString *) string {if (! String. length) {return YES;} if (textField. keyboardType = UIKeyboardTypeNumberPad) {if ([string character: [[NSCharacterSet decimalDigitCharacterSet] invertedSet]. location! = NSNotFound) {return NO;} NSString * updatedText = [textField. text stringByReplacingCharactersInRange: range withString: string]; if (updatedText. length> 11) // 4 was chosen for SSN verification {if (string. length> 1) {// BasicAlert (@ "", @ "This field accepts a maximum of 4 characters. ");} return NO;} return YES ;}