更改 NSTextView 中的文本选择颜色
我正在尝试在 NSTextView 上编写“突出显示”功能。目前,一切进展顺利。您选择一个文本范围,该文本的背景颜色将更改为黄色。然而,虽然它仍然处于选中状态,但背景是所选文本的标准蓝色。如何使标准选择指示器颜色在某些情况下不显示?
谢谢!
I'm trying to write a "highlight" feature on an NSTextView. Currently, everything works great. You select a range of text and the background color of that text changes to yellow. However, while it's still selected, the background is that standard blue of selected text. How do I make that standard selection indicator color not show up in certain cases?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
-[NSTextView setSelectedTextAttributes:...]
。例如:
如果您根本不希望以任何方式指示选择(除了隐藏插入点),您可以简单地传递一个空字典。
另一种选择是监视选择更改并使用 临时属性。请注意,临时属性用于显示拼写和语法错误并查找结果;因此,如果您关心保留 NSTextView 的这些功能,请确保仅添加和删除临时属性,而不是替换它们。
一个例子是(在 NSTextView 子类中):
Use
-[NSTextView setSelectedTextAttributes:...]
.For example:
You can simply pass an empty dictionary if you don't want the selection indicated in any way at all (short of hiding the insertion point).
Another option is to watch for selection changes and apply the "selection" using temporary attributes. Note that temporary attributes are used to show spelling and grammar mistakes and find results; so if you care about preserving these features of NSTextView then make sure only to add and remove temporary attributes, not replace them.
An example of this is (in a NSTextView subclass):