简体   繁体   English

大小不受限制的多行标签,文本顶部对齐?

[英]Multi-line label of unlimited size with the text top-aligned?

I haven't been able to figure it out and most of the techniques coming up in Google have been deprecated: 我一直无法弄清楚,Google提出的大多数技术已被弃用:

I want to have a multi-line label of unlimited size with the text top-aligned. 我想要一个大小不受限制的多行标签,且文本顶部对齐。

How do I do it? 我该怎么做?

If you don't add constraints in your Interface Builder or in code, the view will use it's "default" size in the Interface Builder. 如果您没有在Interface Builder或代码中添加约束,则视图将在Interface Builder中使用其“默认”大小。

Set the numberOfLines of the label to 0. Pin constraints in your Interface Builder from the label's top to it's superview + left and right of the label to it's superview. 将标签的numberOfLines设置为0。接口构建器中的引脚约束,从标签的顶部到其超级视图+标签的左侧和右侧到其超级视图。

Then the label grows with it's content as long as needed. 然后,标签会随着需要的内容一起增长。 You can also add a bottom constraint to the label with a >= X value which limits the label also in it's height when you want to have a max height. 您还可以使用> = X值向标签添加底部约束,当您要具有最大高度时,该限制也将标签的高度限制在标签的高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM