如何根据文本长度使UITextView高度动态? [英] how to make UITextView height dynamic according to text length?

查看:127
本文介绍了如何根据文本长度使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.

这篇关于如何根据文本长度使UITextView高度动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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