在绘制它时,如何手动突出显示Nspopupuptoncell(使用白色而不是黑色绘制)?
-
18-09-2019 - |
题
我有一个由几个单元组成的自定义单元,其中一个是一个nspopupuptoncell。
当绘制我的自定义单元格突出显示时,我想使所有子细胞也突出显示(通常是通过变白)。
例如,如果我打电话给Nstextcell setHighlighted:YES
打电话之前 drawWithFrame:inView
该单元将用白色文字绘制,完全按照我的意愿。
这与nspopupupbuttoncells不起作用。文本只是继续绘制为黑色。
似乎这是可能的,因为将nspopupupbuttoncell放入nstableView的亮点中正确。
有人可以将我指向正确的方向吗?
解决方案
您在哪里托管此自定义+复合NSCELL子类?
- 望远镜:是的,不是您想要的。从文档中:
默认情况下,此方法无济于事。 NSButtoncell类覆盖了此方法,以绘制按钮,其中包括Nscelllightsbybackground,nscelllightsbycontents或nscelllightsbygray指定的外观。
通常,单元格的主机视图将设置单元格的背景样式,并且该单元将在绘制时间使用它来适当显示自己。将背景样式从主电池传播到子细胞。
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSRect textRect, popUpRect;
NSDivideRect(cellFrame, &textRect, &popUpRect, NSWidth(cellFrame) / 2, NSMinXEdge);
/* Draw the text cell (self) */
[super drawInteriorWithFrame: textRect inView: controlView];
/* Draw our compound popup cell - create & release every time drawn only in example */
NSPopUpButtonCell *popUpCell = [[NSPopUpButtonCell alloc] initTextCell: @"popup title"];
[popUpCell setBordered: NO];
[popUpCell setBackgroundStyle: [self backgroundStyle]];
[popUpCell drawWithFrame: popUpRect inView: controlView];
[popUpCell release];
}
如果您将此复合单元格在NstableView中托管,则应该足以获得所选行的正确背景。
如果您在自己的视图中托管此托管,则可能需要做其他工作。 (并且需要在我们提供建议之前提供有关主机环境的更多详细信息。)
不隶属于 StackOverflow