使用iOS故事板动态调整UILabel的高度 [英] Adjust height of UILabel dynamically using iOS storyboard
问题描述
我有一个标签,它是使用iOS Storyboard布局创建的。
I have a label, which has been created using iOS Storyboard layout.
然而,标签的内容是动态的,可以在运行时更改。
Contents of label, however, are dynamic and can change during run time.
如何确保标签的高度根据标签中的内容进行调整。
How do I make sure that label's height gets adjusted based on the content in the label.
我试过:
将行数设置为0
设置编辑器 - >尺寸适合内容
。
但它们不起作用。标签中的文字仅以单行打印,因此屏幕上不会显示某些文字。
But they don't work. Text in label gets printed only in single line, and as a result of that some of text doesn't appear on the screen.
任何帮助都将受到高度赞赏。
Any help would be highly appreciated.
推荐答案
试试这种方式
Try this way
你的标签应为行数为0
将高度约束赋予标签并选择高度约束然后设置大于等于,它会根据内容自动调整高度
give height constraint to lable and select height constraint then set greater than equal , it will automatically adjust height based on content
这篇关于使用iOS故事板动态调整UILabel的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!