Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting an NSTextView

How can I set an NSTextView to an NSAttributedString? I do not want to use a textConainer, and I tried:

[myTextView insertText:myMutableAttributedString];

but it didn't work. Nothing happened...not even a warning or a runtime error. Any help would be appreciated.

like image 245
user657819 Avatar asked Mar 13 '11 23:03

user657819


2 Answers

Textview must be editable to insert.

[myTextView setEditable:YES];
[myTextView insertText:myMutableAttributedString];
[myTextView setEditable:NO];
like image 179
estobbart Avatar answered Sep 28 '22 13:09

estobbart


In Swift 2.2:

myTextView.textStorage?.setAttributedString(myMutableAttributedString)

In Objective-C:

[[myTextView textStorage] setAttributedString:myMutableAttributedString];

like image 20
M. Mayer Avatar answered Sep 28 '22 12:09

M. Mayer