如何将 an 设置NSTextView
为 an NSAttributedString
?我不想使用 textConainer,我尝试过:
[myTextView insertText:myMutableAttributedString];
但它没有用。什么都没有发生……甚至没有警告或运行时错误。任何帮助,将不胜感激。
如何将 an 设置NSTextView
为 an NSAttributedString
?我不想使用 textConainer,我尝试过:
[myTextView insertText:myMutableAttributedString];
但它没有用。什么都没有发生……甚至没有警告或运行时错误。任何帮助,将不胜感激。
Textview 必须可编辑才能插入。
[myTextView setEditable:YES];
[myTextView insertText:myMutableAttributedString];
[myTextView setEditable:NO];
在 Swift 2.2 中:
myTextView.textStorage?.setAttributedString(myMutableAttributedString)
在 Objective-C 中:
[[myTextView textStorage] setAttributedString:myMutableAttributedString];
您应该-setString
在调用该方法之前使用空字符串调用(否则您将文本插入到空字符串对象中):
[myTextView setString:@""];
[myTextView insertText:myMutableAttributedString];
textView 是以编程方式创建的?如果你从 xib 加载 NSTextView,它会很好。