Vibhor Goyal
Vibhor Goyal

Reputation: 2425

Custom background colors for NSTableCellView

I am trying to create a custom NSTableCellView. I subclassed NSTableCellView and I need to have a custom background color and highlight/selection color. Is there a way to do this?

Upvotes: 2

Views: 2962

Answers (1)

Daij-Djan
Daij-Djan

Reputation: 50089

the background as well as the selection is handled by the NSTableRowView view. It CAN (partly) be overwritten by the cell but that's not how it should be at all.

Implement a custom rowview and return that for use behind the row you need to draw

@interface MyRowView : NSTableRowView

there you have:

  • drawBackgroundInRect:
  • drawDraggingDestinationFeedbackInRect:
  • drawSelectionInRect:
  • drawSeparatorInRect:

e.g.

@implementation MyRowView

- (void)drawSelectionInRect:(NSRect)dirtyRect {
        [currentFill fillRect:dirtyRect inContext:[[NSGraphicsContext currentContext]graphicsPort]];
}

@end

SRC: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSTableRowView_Class/Reference/Reference.html

Upvotes: 2

Related Questions