Skip to content

Instantly share code, notes, and snippets.

@mlaster
Created October 15, 2012 21:47
Show Gist options
  • Save mlaster/3895770 to your computer and use it in GitHub Desktop.
Save mlaster/3895770 to your computer and use it in GitHub Desktop.
NSString and character composition
- (BOOL)textView:(UITextView *)inTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
BOOL retValue = NO;
NSUInteger newCharCount = [[inTextView text] length] - range.length + [text length];
NSMutableString *newString = [[inTextView text] mutableCopy];
[newString appendString:text];
NSLog(@"newString: [%@]", newString);
NSLog(@"original newCharCount: %ld", (long)newCharCount);
newCharCount = [newString length];
NSLog(@"new newCharCount: %ld", (long)newCharCount);
if (newCharCount <= self.characterLimit) {
retValue = YES;
}
return retValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment