Hi~ everybody good, so long time not to meet with everybody, say ashamed, recently busy work, already long have not written a blog,
Let's share with you the processing of the digital keyboard limit in iOS---good, nonsense not much to say directly on the code
Did you encounter this problem when you landed with your mobile phone number? is one side want to enter a certain number of digits to limit input, but delete the time also to be able to delete, today small series encountered this problem, solve a half-day, finally solved it, good next to everyone to share
I believe we all know that the input box is used Uitextfield bar, the others do not say, to use TextField words to implement proxy method, the most important point is to set his keyboard mode for the numeric keypad
Txtfield.keyboardtype=uikeyboardtypenumberpad;
Then implement proxy method txtfield.delegate = self; implement proxy protocol
I'm sure you all know his proxy method. One of them is that every time a change is called
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string{
if ([string isequaltostring:@ "]) return YES;
if (Textfield.tag = = Textfield_email_tag && textField.text.length >= 11) {
Phone number
return NO;
}else if (Textfield.tag = = Textfield_passwd_tag && textField.text.length >= 6) {
Password
return NO;
}else{
return YES;
}
}
The red is the key point, after a small series of tangled and observed for a long time, suddenly found that when the Click Delete button return string unexpectedly is @ "", is to seize this point to solve the problem, can limit the number of bits, but also to achieve the deletion-------well, it's time to rest. , we will continue to fight tomorrow-------
Limit digit handling for IOS TextField numeric keypad (ideal for mobile phone login)