How to set background color when selecting NSOutlineView row

I have a big problem and I can’t solve it.

I have NSOutlineViewone that contains NSButtonCellone that is attached to arrayController, after which it installs it Titleand based on some value the image is set against the background of the cell by codes.

The image is set using these codes.

[cell setImage:[NSImage imageNamed:@"sbWarn.png"]];
[cell setImagePosition:NSImageOverlaps];
[cell setBackgroundColor:[NSColor clearColor]];

The problem is that when I select a row, the selected row shows a black background. I tried all possible ways of setting the background like clearColor etc.

How can I make him look good.

+3
source share
2 answers

. , , , , , :

// Outline view delegate

-(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {

    NSUInteger rowNo = [outlineView rowForItem:item];

    NSColor *backgroundColor;
    if ( [[outlineView selectedRowIndexes] containsIndex:rowNo] ) {
        backgroundColor = // Highlighted color;
    }
    else {
        backgroundColor = // Normal background color;
    }

    [cell setBackgroundColor: backgroundColor];
}

, , .

, , outlineView:dataCellForTableColumn:item:.

NSButtonCell *cell = [[NSButtonCell alloc] init];

[cell setBezelStyle:NSRegularSquareBezelStyle];
[cell setButtonType:NSToggleButton];
[cell setBordered:NO];
[cell setTitle:@""];
[cell setImage:[NSImage imageNamed:@"green.png"]];
[cell setAlternateImage:[NSImage imageNamed:@"red.png"]];
[cell setImagePosition:NSImageOverlaps];
+1

, " ". .

0

All Articles