Skip to content

Instantly share code, notes, and snippets.

@toughrogrammer
Last active December 20, 2015 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toughrogrammer/6155275 to your computer and use it in GitHub Desktop.
Save toughrogrammer/6155275 to your computer and use it in GitHub Desktop.
Text length
/**
* 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