iPhone - 自定义字体需要额外的内存吗?

发布于 2024-11-16 02:08:15 字数 423 浏览 9 评论 0原文

我需要为我的 UILabel 使用外部自定义字体。我设法做到了并且它正在发挥作用。

我的应用程序中有大约 50 个 UILabel。每个 UILabel 都具有与我的应用程序嵌入的相同的自定义字体。

所有 50 个 UILabel 都会一次性加载到内存中。

每个 UILabel 的文本大约是 200 字节的 NSString,所有文本的总和大约是 1K - 2K 字节。我之前犯了一个错误,将每个 UILabel 的文本写为 1K - 2K,抱歉。

我注意到一件事,如果我将自定义字体应用于 UILabels,内存成本非常高,比没有自定义字体多 30 - 40MB。

这可能吗?

我的应用程序非常简单,目前只显示 5 个页面,每个页面有 10 个 UILabels。所以我认为不会存在其他地方或错误

I need to use an external custom font for my UILabel. I managed to do it and it is working.

I have totally like 50 UILabel in my app. Each UILabel has the same custom font that I embed with my app.

All 50 UILabels are loaded at one time into the memory.

Each UILabel's text is around 200 bytes of NSStrings, the sum of all texts are around 1K - 2K bytes. I made a mistake previously by writing each UILabel's text is 1K - 2K, sorry.

I noticed one thing, if I apply the custom font to the UILabels, the memory costs very high, like 30 - 40MB extra more than without custom fonts.

Is this possible?

My app is very simple currently just show 5 pages, each page has 10 UILabels. So no other places or bugs would exist, I think

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

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

发布评论

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

评论(1

自此以后,行同陌路 2024-11-23 02:08:15

如果标签有 1k - 2k 的文本,我确信其中 50 个无法一次显示全部。这里采用的方法类似于 UITableView 的工作方式,当用户滚动、切换选项卡等时,仅显示用户可见的标签并卸载其他标签。这将减少内存峰值,您只需要为显示的标签加载自定义字体。

If the labels have 1k - 2k worth of text I am sure that 50 of them can not be displayed all at once. The approach to take here is similar to how the UITableView works, as the user scrolls, switch tabs, etc then only display labels that will be visible to the user and unload the others. This will reduce the memory peak and you will only need to have the custom fonts loaded for the displayed labels.

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