4

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;
4

0 回答 0