更新时间: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