There are a lot of restrictions on the Internet TextField input length method, but I do not think it is perfect, accurate to say is not in line with the actual development requirements, so here to tidy up the TextField limit the length of the input method.
What I'm using is not the listening method but the most different proxy implementations, why not use listening???
When you see this article is likely to be a matter of distress that is the use of listening to limit the length of input can not be perfect control of the input content.
To give a simple example:
You want to limit the input length to 30 characters, and when you enter 30 characters after the monitor can really good control does not allow you to continue typing, but the problem comes along, when you move the cursor to the middle of the input, you can continue typing this input is very annoying because when you enter your cursor will move to the end, and limit your continued input, but the inner pride you just entered remains in the middle of the text, which is very inconsistent with the requirements.
So using proxies here can be a good implementation of the results we want, just a few lines of code that would like to help you.
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) String {
if (TextField = = Self.livethemetextfield) {
//if time here in order to get the delete operation, If there is no secondary if will cause the deletion of the key after the word limit can not use the consequences.
if (range.length = = 1 && string.length = 0) {return
YES;
}
So easy
else if (self.liveThemeTextField.text.length >=) {
Self.liveThemeTextField.text = [ Textfield.text substringtoindex:30];
return NO;
}
Return YES
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.