1.设置textfiled代理
2.在输入框文字发生改变时计算
- (void)textViewDidChange:(UITextView*)textView {
///> 计算文字高度
CGFloat height = ceilf([textView sizeThatFits:CGSizeMake(textView.frame.size.width, MAXFLOAT)].height);
if(height >=100) {
textView.scrollEnabled = YES; ///> 当textView高度大于等于最大高度的时候让其可以滚动
height =100; ///> 设置最大高度
}
///> 重新设置frame, textView往上增长高度
textView.frame=CGRectMake(50,10,self.view.bounds.size.width-100, height);
[textViewlayoutIfNeeded];
}