1
votes

I'm trying to set an attributed string in an NSTextView, and if the text is taller than the text view, the text doesn't show up at all unless you scroll the text box.

There aren't many posts about attributed strings in NSTextView, so maybe I'm just doing something wrong. Here's how I'm setting the text:

[[self.textView textStorage] appendAttributedString:attributedString];
2

2 Answers

2
votes

You have to programmatically tell the NSTextView it has to make the new string visible:

NSUInteger length = [[self.textView string] length];
[self.textView scrollRangeToVisible:NSMakeRange(length,0)];

This should work independent of if the appended string is a "simple" string or an attributed string.

0
votes

Call -beginEditing before making a series of changes to the text storage and -endEditing afterward. See Text System Storage Layer Overview: Changing Text Storage.