- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSUInteger newLength = (text_View.text.length - range.length) + text.length;
if(newLength <= 140)
{
return YES;
} else {
NSUInteger emptySpace = 140 - (text_View.text.length - range.length);
textView.text = [[[textView.text substringToIndex:range.location]
stringByAppendingString:[text substringToIndex:emptySpace]]
stringByAppendingString:[textView.text substringFromIndex:(range.location + range.length)]];
return NO;
}
}
No comments:
Post a Comment