如何根据文本长度使UITextView高度动态?
问题描述:
正如你在这张图片中看到的那样
As you can see in this image
UITextView
根据文字长度改变它的高度,I想要根据文字长度调整它的高度。
the UITextView
changes it's height according to the text length, I want to make it adjust it's height according to the text length.
*我看到了其他问题,但那里的解决方案对我不起作用
答
此工作对我来说,所有其他解决方案都没有。
this Works for me, all other solutions didn't.
func adjustUITextViewHeight(arg : UITextView)
{
arg.translatesAutoresizingMaskIntoConstraints = true
arg.sizeToFit()
arg.scrollEnabled = false
}
在Swift 4中, arg.scrollEnabled = false
的语法已更改为 arg.isScrollEnabled = false
。
In Swift 4 the syntax of arg.scrollEnabled = false
has changed to arg.isScrollEnabled = false
.