当我们增加 fontSize 时,标签内的文本如何调整?

发布于 2024-09-08 07:14:18 字数 172 浏览 2 评论 0原文

在某些应用程序中,我发现我们可以选择增加或减少标签内文本的字体大小。但是当我们调整它时,标签会自动增加其高度以包含它。每次增加或减少字体大小时,如何获取标签的高度?

在某些情况下,例如加载新闻应用程序时,只会有文本。但突然图像出现,文本重新调整自身以包含它。它自己是如何做到的?

有人请帮助我...

In some of the applications, I have seen that we have an option to increase or decrease the fontSize of the text inside the label. But when we adjust it, the label automatically increases its height to contain it. How do we get the height of the label everytime we increase or decrease the fontsize?

And in some cases like news applications when it loads, there will be text only. But suddenly the image comes and the text readjusts itself to contain it. How does it do it by itself?

Someone plz help me...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

烟花肆意 2024-09-15 07:14:18
CGSize textSize = [@"foobar" sizeWithFont:[UIFont boldSystemFontOfSize:18]];

签出 NSString UIKit 添加。它有几个方法可以让你询问一个字符串在使用给定字体渲染时有多大。有了这些信息,您应该能够通过一点数学来根据需要进行调整。

此外,在某些情况下,它可能是网络视图。如果是这种情况,HTML/CSS 会自动流动内容以保持整洁。

CGSize textSize = [@"foobar" sizeWithFont:[UIFont boldSystemFontOfSize:18]];

Checkout NSString UIKit Additions. It has got a couple of these methods that let you ask a string how big it would be when rendered with a given font. With that information, you should be able to adjust things however you need with a little math.

Also, in some cases, it may be a web view. If this is the case, HTML/CSS sort of flows stuff around automatically in order to keep things tidy.

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