Question: I've looked at a number of questions but can't find a **good** solution for a View-Based NSOutlineView

[Coloring NSTableView Text per row](https://stackoverflow.com/questions/2786362/coloring-nstableview-text-per-row)

[Change color of NSTableViewCell](https://stackoverflow.com/questions/2879154/change-color-of-nstableviewcell)

[Custom background colors for NSTableCellView](https://stackoverflow.com/questions/16369061/custom-background-colors-for-nstablecellview)

I'm trying to set each row to whatever color I want. I've read somewhere that I need to subclass `NSTableRowView` which I've now done.

According to the [AppleDocs](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSTableRowView_Class/Reference/Reference.html), I see the following methods:

```
– drawBackgroundInRect:
– drawDraggingDestinationFeedbackInRect:
– drawSelectionInRect:
– drawSeparatorInRect:

```

How would I go about setting the background color for the individual rows? Am I going the wrong route above?

**Edit: below (also edited title)**

Since i'm using an NSOutlineView and not a NSTableView, when i change the background color of the cells the image looks like the following. The disclosure arrows to the left is not colored. Is there any way to change the color of the whole row for the NSOutlineView?

![this](https://i.stack.imgur.com/p9rRj.png)

Answer: 
Came up with a solution. Implemented the following.

```
-(void)outlineView:(NSOutlineView *)outlineView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
    [self updateRowViewBackColorforItem:[outlineView itemAtRow:row]];
}

-(void)updateRowViewBackColorforStep:(myCustomItem *)customItem {
    static NSColor *color1;
    static NSColor *color2;
    static NSColor *color3;

    if (color1 == nil) {
        sharedcolorHeader = [NSColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0];
    }
    if (color2 == nil) {
        sharedcolorChildren = [NSColor colorWithCalibratedRed:(x/255.0f) green:(y/255.0f) blue:(z/255.0f) alpha:1.0];
    }
    if (color3 == nil) {
        normalColor = [NSColor colorWithCalibratedRed:(255/255.0f) green:(255/255.0f) blue:(255/255.0f) alpha:1.0];
    }

    NSInteger row = [stepOutlineView rowForItem:step];
    if (row < 0) return;

    NSTableRowView *view = [myOutlineView rowViewAtRow:row makeIfNecessary:NO];

   if ([customItem type] == 1) {
        [view setBackgroundColor:sharedcolorHeader];
    } else if([customItem type] == 2) {
        [view setBackgroundColor:sharedcolorChildren];
    } else {
        [view setBackgroundColor:normalColor];
    }
}

```
You could subclass NSTableViewCell, and add a method to it which sets its color. 

NSTableViewCell is already a subclass of NSView, so in your subclass, you would add the following method:

```
- (void)setBackgroundColor {
    self.layer.backgroundColor = CGColorCreateGenericRGB(0, 0, 0, 1.0f); // or whatever color
}

```

Or something like that. You'll probably want to have the color be a param to the method. Then, in your table view delegate, you can set the color depending on the row index passed to the delegate method. For example:

```
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil)
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    if (indexPath.row % 2) {
        [cell setBackgroundColor:[UIColor redColor]]; // or something like that
    }
}

```