【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;
}

 

posted on 2021-07-17 13:13  wp7ers  阅读(306)  评论(0编辑  收藏  举报