搜了一下,网上的方法都有点问题。看看最新方法:
#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView{
CGRect textViewFrame = textView.frame;
CGSize textSize = [textView sizeThatFits:CGSizeMake(CGRectGetWidth(textViewFrame), 100.0f)];
if (textSize.height > 52) {//3行了 两行52 三行70
while (textSize.height > 52) {
textView.text = [textView.text substringToIndex:[textView.text length]-1];
textSize = [textView sizeThatFits:CGSizeMake(CGRectGetWidth(textViewFrame), 100.0f)];
}
}
}