UITextView - setting font size of attributedText slow?

倾然丶 夕夏残阳落幕 提交于 2019-12-10 15:19:13

问题


I'm trying to change the font size of my UITextView's text, which is using attributed text, with the following:

UIFont *font = [self.textView.font fontWithSize:value];
NSDictionary *attributes = @{ NSFontAttributeName: font };

NSMutableAttributedString *attrString = [self.textView.attributedText mutableCopy];
[attrString addAttributes:attributes range:NSMakeRange(0, attrString.length)];
self.textView.attributedText = attrString;

However, using this in combination with a slider causes a noticeable slow down. Am I doing this correctly? Simple setting the font size of the textView.font property did not work.

This is how I'm setting the attributed text in the first place:

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"Neutra church-key brunch farm-to-table disrupt skateboard, bushwick next level organic gentrify street art. Pop-up echo park pork belly pour-over. Bespoke meggings put a bird on it, plaid hashtag farm-to-table YOLO freegan pug pickled jean shorts quinoa gentrify forage. Tumblr butcher echo park, small batch mumblecore banjo trust fund intelligentsia bushwick VHS raw denim."];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(59, 13)];
[string addAttribute:(NSString*)NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:(NSRange){59, 13}];

textView.attributedText = string;

来源:https://stackoverflow.com/questions/16289481/uitextview-setting-font-size-of-attributedtext-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!