xcode 使用 iOS 故事板动态调整 UILabel 的高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38471569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adjust height of UILabel dynamically using iOS storyboard
提问by user462455
I have a label, which has been created using iOS Storyboard layout.
我有一个标签,它是使用 iOS Storyboard 布局创建的。
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.
如何确保根据标签中的内容调整标签的高度。
I tried:
我试过:
Setting number of lines to 0
将行数设置为 0
Setting Editor -> Size to Fit Content
.
设置Editor -> Size to Fit Content
。
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.
任何帮助将不胜感激。
回答by karthikeyan
回答by kai
Please check your constraints. You can't set label's height constraint.If superview's height is fixed,you can't set top and bottom constraint at same time.Because it means you set the height constraint of label. So you can must fix label width and you can't fix label height.
请检查您的约束。不能设置label的高度约束。如果superview的高度是固定的,则不能同时设置top和bottom约束,因为这意味着你设置了label的高度约束。所以你必须固定标签宽度,你不能固定标签高度。