如何在绘制 NSPopUpButtonCell 时手动突出显示它(使用白色而不是黑色绘制)?
我有一个由多个单元组成的自定义单元,其中之一是 NSPopUpButtonCell。
当突出显示我的自定义单元格时,我想让所有子单元格也突出显示(通常通过变成白色)。
例如,对于 NSTextCell,如果我在调用 drawWithFrame:inView
之前调用 setHighlighted:YES
,则单元格将用白色文本绘制,完全按照我想要的那样。
这不适用于 NSPopUpButtonCells。 文本继续绘制为黑色。
看起来这应该是可能的,因为将 NSPopUpButtonCell 放入 NSTableView 中会正确突出显示。
有人可以指出我解决此问题的正确方向吗?
I've got a custom cell composed out of several cells, one of which is an NSPopUpButtonCell.
When drawing my custom cell highlighted, I want to cause all the sub-cells to highlight as well (typically by turning white).
With, for example an NSTextCell, if I call setHighlighted:YES
before calling drawWithFrame:inView
the cell will be drawn with white text, exactly as I want it.
This does not work with NSPopUpButtonCells. The text just continues to draw as black.
It seems like this should be possible, since dropping an NSPopUpButtonCell into an NSTableView highlights properly.
Can somebody point me in the right direction for fixing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里托管这个自定义+复合 NSCell 子类?
-setHighlighted:YES 不是您要找的。 从文档中:
通常,单元格的宿主视图将设置单元格的背景样式,并且单元格将在绘制时使用它来适当地显示自身。 将背景样式从主单元格传播到子单元格。
如果您在 NSTableView 中托管此复合单元格,那么这应该足以为所选行获取正确的背景。
如果您以自己的方式托管此内容,则可能需要做额外的工作。 (并且需要提供有关主机环境的其他详细信息,然后我们才能提供建议。)
Where are you hosting this custom+composite NSCell subclass?
-setHighlighted:YES isn't what you are looking for. From the documentation:
Typically the host view for a cell will set the cell's background style, and the cell will use that at draw time to display itself appropriately. Propagate the background style from the master cell to the sub-cells.
If you are hosting this composite cell in an NSTableView, that should be sufficient to get the correct background for selected rows.
If you are hosting this in your own view, you may need to do additional work. (And need to provide additional details about the host environment before we can offer advice.)