UILabel 没有显示更新后的高度?

UILabel not showing up updated height?

在IB中,标签高度为50。 我已经在标签中添加了文本,直到它扩展了它的高度。 我试着检查标签高度,但它仍然显示 50。 例如:

print(label.bounds.size.height) //50
label.text = "Long text more than 200 chars"
print(label.bounds.size.height) // still shows 50.

如何获取更新的标签高度?

试试这个方法:

label.numberOfLines = 0

print(label.bounds.size.height) //50

label.text = "Long text more than 200 chars"

label.sizeToFit()

print(label.bounds.size.height)