Last active
December 20, 2015 15:38
-
-
Save toughrogrammer/6155275 to your computer and use it in GitHub Desktop.
Text length
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
/** | |
* Delegate method called before the text has been changed. | |
* @param textField The text field containing the text. | |
* @param range The range of characters to be replaced. | |
* @param string The replacement string. | |
* @return YES if the specified text range should be replaced; otherwise, NO to keep the old text. | |
*/ | |
- (BOOL)textField:(UITextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | |
{ | |
NSUInteger oldLength = [textField.text lengthOfBytesUsingEncoding:(0x80000000 + kCFStringEncodingDOSKorean)]; | |
NSUInteger replacementLength = [string lengthOfBytesUsingEncoding:(0x80000000 + kCFStringEncodingDOSKorean)]; | |
NSUInteger rangeLength = range.length; | |
NSUInteger newLength = oldLength - rangeLength + replacementLength; | |
CCLOG("old:%d, replace:%d, range:%d, new:%d", oldLength, replacementLength, rangeLength, newLength); | |
return oldLength/2 <= 5; // 5글자만 입력되도록 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment