简体   繁体   English

如何将标签文本与顶部对齐

[英]How to Align Label Text to the Top

I have a label in a UIScrollView that gets its string contents from a website. 我在UIScrollView中有一个标签,它从网站获取其字符串内容。 I was wondering how to make the label display the text so that it is not centered, but is top aligned. 我想知道如何使标签显示文本,使其不居中,但是顶部对齐。 The text in the label keeps displaying in the center of the label, which looks awkward in a scroll view. 标签中的文本一直显示在标签的中心,在滚动视图中看起来很尴尬。 I want the label to display the text starting from the top. 我希望标签从顶部开始显示文本。 Thanks! 谢谢!

如果使用自动布局,则需要将高度约束调整为“小于或等于”,并将常量更新为所需的最大值。

Call -sizeToFit on this label after setting it's text. 在设置文本后,在此标签上调用-sizeToFit If all you have in this scrollview is a label, you could also adjust it's contentSize after that. 如果此滚动视图中的所有内容都是标签,则可以在此之后调整它的contentSize。

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

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