相关疑难解决方法(0)

在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
查看次数

添加轻击手势到UILabel的一部分

我有一个像这样的NSAttributedString:

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"testing it out @clickhere"];
NSInteger length = str.length;
[str addAttribute:NSForegroundColorAttributeName value:[UIColor bestTextColor] range:NSMakeRange(0,length)];
Run Code Online (Sandbox Code Playgroud)

NSMutableAttributedString设置为UILabel,如下所示:

label.attributedText = str;
Run Code Online (Sandbox Code Playgroud)

如何在另一个视图控制器中为上面的字符串中的'@clickhere'做出一个轻击手势(或可点击的东西)?

谢谢!

iphone nsattributedstring uilabel ios uitapgesturerecognizer

6
推荐指数
1
解决办法
1万
查看次数