views:

41

answers:

2

How can I set the selection color? In this case, it's the color of a selection in an NSTableView

edit:

Here's my subclass:

- (void)highlightSelectionInClipRect:(NSRect)clipRect
{
NSBezierPath *windowPath;
windowPath = [NSBezierPath bezierPathWithRect:clipRect];
[[NSColor greenColor] set];
[windowPath fill];
}

The only problem is that it puts the color in the background, not as the color that's used when I highlight a row.

+2  A: 

Write a subclass of NSTableView in which you override the highlightSelectionInClipRect: method, and make your table view an instance of that subclass.

Your implementation of the method should set the selection color, then fill the rectangle with that color.

Note that the selection color is user-configurable (see the various highlight-color methods of NSColor), so you shouldn't override the selection color without a very good reason.

If you want to make the selection highlight a gradient, like a source list, that's much easier: Set the table view's highlight style. You don't need to subclass, and you can set this property in IB.

Peter Hosey