我需要对 NSTextFieldCell 进行一些高级文本样式设置
首先,我只需要文本上的一些背景颜色。就像 F 脚本浏览器中的标题
设置 [cell setBackgroundColor: [NSColor blueColor]];为整个单元格空间着色,而不仅仅是文本。我还需要带下划线和删除线的文本。为了使内容可读,我最终想更改样式项目上选择的颜色(前景/背景)。
我可以使用默认的 NSTextFieldCell 执行此操作吗?
First i need some background color on the text only. Like the headers in the F-Script Browser
Setting [cell setBackgroundColor: [NSColor blueColor]]; colors the whole cell space not only the text. Also i would need underlined and strikeout text. And to make things readable i would finally like to change the colors (foreground/background) of the selection on the styled items.
Can i do this with the default NSTextFieldCell ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几乎所有这些事情都是 NSAttributedString 的工作。只要文本字段单元格启用了富文本,它就应该接受属性字符串作为其对象值。
至于选择颜色,请记住 NSTextFieldCell 是 NSActionCell 的一种,而 NSActionCell 是 NSCell 的一种。 NSCells 有 可以重写以返回不同的突出显示颜色的方法。这涵盖了背景;对于前台,您可能必须 自己至少绘制突出显示的部分。您也许可以在该方法中充分利用混合模式。
Nearly all of these things are jobs for NSAttributedString. As long as the text field cell has rich text enabled, it should accept an attributed string as its object value just fine.
As for the selection color, remember that an NSTextFieldCell is a kind of NSActionCell, and an NSActionCell is a kind of NSCell. NSCells have a method you can override to return a different highlight color. That covers the background; for the foreground, you may have to draw at least the highlighted portion yourself. You may be able to make good use of blend modes in that method.