I am using BGHUDAppKit
for an outline view within a HUD-style (black) NSPanel
. As such the text in my outline view cells is light gray or white开发者_运维知识库. Unfortunately this means that when I hover to bring up a tooltip for a cell's value, it shows up as light gray text on yellow, which is illegible.
How can I set the text color for the tooltip, or is there a way that I can modify the control itself (without changing its appearance) to work better with the tooltip mechanism?
You can override - (void)drawWithExpansionFrame:(NSRect)cellFrame inView:(NSView *)view
in a NSCell subclass to draw whatever you want in the (tool tip) expansion frame.
Based on Adem Preble's suggestion, I ended up with a NSTextField
subclass, which overrides drawWithExpansionFrame
, and uses a simple color toggle trick:
@implementation MyCustomTextField
- (void)drawWithExpansionFrame:(NSRect)contentFrame inView:(NSView *)view {
NSColor *originalColor = self.textColor;
self.textColor = NSColor.labelColor; // Or any other NSColor
[super drawWithExpansionFrame:contentFrame inView:view];
self.textColor = originalColor;
}
@end
This works because the expansion tooltip with the adjusted color covers the text field behind it, with the freshly reset color.
精彩评论