We can use the UITextField’s delegate method
- (BOOL)textField: (UITextField *)textField shouldChangeCharactersInRange: (NSRange)range replacementString: (NSString *)string
to set the maximum character length.
This can be done by doing the following:
#define MAX_LENGTH 10 - (BOOL)textField: (UITextField *)textField shouldChangeCharactersInRange: (NSRange)range replacementString: (NSString *)string { if (textField.text.length >= MAX_LENGTH && range.length == 0) { return NO; } else { return YES; } }
how this method is called. my text field name is sampleText. Where i need to change this code. And i am developing calculator application.So i want to limit the text field. And please some code about where i need to write delegate and how can i call this method.
thanks in advance.
Hi!!
I have a one question: If the user paste one string ? When type no problem. But if the data that is paste have more lenght than maxsize. have problem
Name (required)
Mail (will not be published) (required)
Website
Please note: JavaScript is required to post comments. Spam protection by WP Captcha-Free