且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式在 UItextview 上设置动态高度以适应内容

更新时间:2023-02-09 18:41:02

为了回答最初的问题,您对 sizeThatFits 的调用不知道 TextView 应该有多高,因为它不知道有多宽你想要它.我认为在 sizeThatFits 行之前,您需要以下内容:

To answer the original question, your call to sizeThatFits has no idea how tall the TextView should be because it has no idea how wide you want it to be. I think before the sizeThatFits line you want the following:

textView.frame.size.width = self.view.frame.width - 2 * margin