500 个标签的内存管理

发布于 2024-11-23 16:30:34 字数 219 浏览 3 评论 0原文

我有一个视图,上面有数百个单独的 UILabel。它有效,但显然是系统上的一个沼泽。该应用程序运行缓慢,直到另一种方法释放此视图以及所有标签。

但是,我知道经常需要在屏幕上放置这么多文本,所以我想知道如何更好地做到这一点。每个标签都根据其他参数放置在特定位置,因此它不能只是一个大文本视图。

我猜想更好的方法是使用 Open GL 字体或类似的东西在屏幕上“绘制”文本。还有其他建议或建议吗?

I have a view with several hundred individual UILabels on it. It works, but it is clearly a bog on the system. The app is sluggish until another method releases this view with all the labels.

However, I know that it is necessary often to put this amount of text on a screen, so I'm wondering how is a better way to do it. The labels are each placed in a specific location based on other parameters, so it cannot just be one big textview.

I am guessing the better way to do this is to "draw" the text on the screen using an Open GL Font or something like that. Any other suggestions or advice?

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

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

发布评论

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

评论(2

╭⌒浅淡时光〆 2024-11-30 16:30:34

您还可以检查 NSString 的添加: NSString UIKit添加
示例用法:

- (void)drawRect:(CGRect)rect
{
        NSString *temperature = [NSString stringWithFormat:@"%@\n%d / %d", weatherItem.place, high, low];
        [[UIColor blackColor] set];
        [temperature drawInRect:CGRectMake(15.0, 5.0, 50.0, 40.0) withFont:[UIFont systemFontOfSize:11.0]];
}

You can also check Additions to NSString: NSString UIKit Additions
Sample usage:

- (void)drawRect:(CGRect)rect
{
        NSString *temperature = [NSString stringWithFormat:@"%@\n%d / %d", weatherItem.place, high, low];
        [[UIColor blackColor] set];
        [temperature drawInRect:CGRectMake(15.0, 5.0, 50.0, 40.0) withFont:[UIFont systemFontOfSize:11.0]];
}
自找没趣 2024-11-30 16:30:34

使用 Core Graphics 将文本绘制到 drawRect 方法中的 CGContext 上。请参阅 CGContext 文档<的绘图文本部分< /a>

Use Core Graphics to draw the text onto the CGContext in your drawRect method. See the Drawing Text section of the CGContext docs

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