小编Ben*_*Ben的帖子

在iOS 8下,NSAttributedString性能更差

在iOS 8(和8.1 beta)下,创建NSAttributedString的性能远远低于7(2-3x).如果您在同一视图上使用多个实例,则这一点尤其明显,加载4个不同的标签将导致用户点击并显示新视图时延迟超过一秒.

不幸的是,你甚至无法把它扔进另一个线程,因为它在幕后使用WebKit.我向Apple提交了一个错误,但我需要有关变通方法或更好的实现方法的想法.

在viewDidLoad中:

self.labelOne.attributedText = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
                                                     documentAttributes:nil
                                                                  error:&error];
Run Code Online (Sandbox Code Playgroud)

快速示例项目:https://github.com/BenSS/AttributedStringTest

更新:
iOS9再次改进了东西,因此速度并没有完全破坏UI交互.不幸的是,它还没有像iOS7那样快.(用演示自己测试!)

objective-c nsattributedstring ios ios8 ios9

7
推荐指数
1
解决办法
4825
查看次数

标签 统计

ios ×1

ios8 ×1

ios9 ×1

nsattributedstring ×1

objective-c ×1