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

发布于 2024-12-01 23:16:11 字数 119 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

女皇必胜 2024-12-08 23:16:11

设置文本后,在此标签上调用 -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.

绾颜 2024-12-08 23:16:11

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文