如何将标签文本对齐到顶部
我在 UIScrollView 中有一个标签,它从网站获取其字符串内容。我想知道如何使标签显示文本,使其不居中,而是顶部对齐。标签中的文本始终显示在标签的中心,这在滚动视图中看起来很尴尬。我希望标签从顶部开始显示文本。谢谢!
I have a label in a UIScrollView that gets its string contents from a website. 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置文本后,在此标签上调用
-sizeToFit
。如果此滚动视图中只有一个标签,您还可以在此之后调整它的 contentSize。Call
-sizeToFit
on this label after setting it's text. If all you have in this scrollview is a label, you could also adjust it's contentSize after that.如果您使用自动布局,则需要将高度约束调整为“小于或等于”,并将常量更新为所需的最大值。
If you use auto layout, you need to adjust your constraint of height to "Less than or equals" and update your constant to the maximum you need.