UITextView自动高度 [英] UITextView Auto Height

查看:71
本文介绍了UITextView自动高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将UITextView扩展或缩小到其中文本的大小,然后使UIScrollview展开或缩小以适合UITextView

How do I make a UITextView expand or shrink to the size of the text inside it and then make the UIScrollview Expand or shrink to fit the UITextView

推荐答案

CGRect frame;
frame = textiew.frame;
frame.size.height = [textView contentSize].height;
textView.frame = frame;

有一点需要注意的是,正确的contentSize仅在 之后可用已使用addSubview将UITextView添加到视图中,并为其分配了文本。在此之前,它等于frame.size

One thing to note is that the correct contentSize is only available after the UITextView has been added to the view with addSubview and the text is assigned to it. Prior to that it is equal to frame.size

这篇关于UITextView自动高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆