- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (text.length == 0) return YES;
NSInteger existedLength = textView.text.length;
NSInteger selectedLength = range.length;
NSInteger replaceLength = text.length;
if (existedLength - selectedLength + replaceLength > 7)
{
return NO;
}
return YES;
{
if (text.length == 0) return YES;
NSInteger existedLength = textView.text.length;
NSInteger selectedLength = range.length;
NSInteger replaceLength = text.length;
if (existedLength - selectedLength + replaceLength > 7)
{
return NO;
}
return YES;
}
-(void)textViewDidChange:(UITextView *)textView{
if ([textView.text length]>7) {
textView.text = [textView.text substringToIndex:7];
[[[UIAlertView alloc] initWithTitle:@"警告" message:@"字数超过限制" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
self.themStr = textView.text;
} else {
self.themStr = textView.text;
}
}