Set the background color of selected text in NSTextView?

隐身守侯 提交于 2019-12-06 11:47:20

As you've discovered, the selected text attributes only apply to the text while it's selected. If you want to add some attributes to the selected text that persist, you'll need to apply those attributes to the underlying NSTextStorage object (which is just a subclass of NSMutableAttributedString).

The way to do that is to use the text view's textStorage method and then apply the attributes using the addAttributes:range: method (or setAttributes:range: depending on whether you want to add to the existing text attributes or replace them altogether).

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