- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ CGFloat textHeight = textView.contentSize.height; NSLog(@"%@",[NSString stringWithFormat:@"%f",textHeight]); if (range.location > COMMENTMAXTEXT )//([textView.text length] + [text length] - range.length >250 { _textView.text = [_textView.text substringToIndex:COMMENTMAXTEXT]; return NO; } else if (textView.contentSize.height >= COMMENTMAXROWHEIGHT ){//正好是最8行 textView.text = [textView.text substringToIndex:[textView.text length]-1]; return NO; } else { return YES; } } - (void)textViewDidChange:(UITextView *)textView{ if(textView.contentSize.height >= COMMENTMAXROWHEIGHT) { [MBProgressHUD showError:@"最多只能输入8行"]; _textView.text = [textView.text substringToIndex:[textView.text length]-1]; }else if(textView.text.length > COMMENTMAXTEXT){ _textView.text = [_textView.text substringToIndex:COMMENTMAXTEXT]; [MBProgressHUD showError:@"最多只能输入250个字"]; } // NSLog(@"%s",__func__); }