我需要对 NSTextFieldCell 进行一些高级文本样式设置

发布于 2024-09-17 11:38:46 字数 273 浏览 2 评论 0原文

首先,我只需要文本上的一些背景颜色。就像 F 脚本浏览器中的标题

alt text

设置 [cell setBackgroundColor: [NSColor blueColor]];为整个单元格空间着色,而不仅仅是文本。我还需要带下划线和删除线的文本。为了使内容可读,我最终想更改样式项目上选择的颜色(前景/背景)。

我可以使用默认的 NSTextFieldCell 执行此操作吗?

First i need some background color on the text only. Like the headers in the F-Script Browser

alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海蓝天 2024-09-24 11:38:47

几乎所有这些事情都是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文