iOS开发 - UITextView输入时高度自适应
程序员文章站
2022-06-01 10:14:21
...
// 设置边距 依次为:上,左,下, 右
textView.textContainerInset = UIEdgeInsetsMake(20,20, 20, 20);
-(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://my.oschina.net/gwlCode/blog/1577062