【iOS知识汇】UITextView输入时高度随文字输入变化高度。

1.UITextFeild是不支持多行的。

2.动态改变高度的方法。最简单方法如下。

-(void)textViewDidChange:(UITextView *)textView 
{
    //获得textView的初始尺寸 将scrollEnable设置为NO。
    CGFloat width = CGRectGetWidth(textView.frame);
    CGFloat height = CGRectGetHeight(textView.frame);
    CGSize newSize = [textView sizeThatFits:CGSizeMake(width,MAXFLOAT)];
    CGRect newFrame = textView.frame;
    newFrame.size = CGSizeMake(fmax(width, newSize.width), fmax(height, newSize.height));
    textView.frame= newFrame;
}
原文地址:https://www.cnblogs.com/mamamia/p/15023219.html