Created
July 24, 2013 18:03
-
-
Save kishikawakatsumi/6072953 to your computer and use it in GitHub Desktop.
Set Max Character Length UITextField (works with Japanese input method)
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
... | |
[textField addTarget:self action:@selector(editingChanged:) forControlEvents:UIControlEventEditingChanged]; | |
... | |
#define MAXLENGTH 3 | |
- (IBAction)editingChanged:(id)sender | |
{ | |
UITextField *textField = sender; | |
UITextRange *textRange = textField.markedTextRange; | |
if (!textRange.start || !textRange.end) { | |
if (textField.text.length > MAXLENGTH) { | |
textField.text = [textField.text substringToIndex:MAXLENGTH]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment