2013-10-20 323 views
2

在我的自定义NSTableCellView我重写-(void)drawRect这样(我这样做是因为我有模式图像背景NSWindow我需要只显示cellView NSLabel):
NSTableCellView透明背景

- (void)drawRect:(NSRect)dirtyRect 
{ 
    [[NSColor clearColor] setFill]; 
    NSRectFill(dirtyRect); 
    [super drawRect:dirtyRect]; 
} 

和我得到这样的结果,它使整个NSWindow透明:

enter image description here

我想导致像VOX mac app做(看红色月食,你看cellView是与父母的背景图像透明):

enter image description here

回答

0

我已经解决了我的问题:
我在Xcode中使用MMScroller库(请阅读它的安装过程中),与一些技巧:

我的tableView 属性Instector核对交替行。然后,只需在属性Inspector中完成这项工作,将tableView背景色设置为clearColor。

enter image description here

+0

_tableView.usesAlternatingRowBackgroundColors = NO; – johndpope

0

那么有两种方法可以更改单元格的颜色。 1)实施委托: -

- (void)tableView:(NSTableView *)tableView 
    willDisplayCell:(id)cell 
    forTableColumn:(NSTableColumn  
    *)tableColumn 
    row:(NSInteger)row 

然后是exract单元格值的基础上,并使用setBackgroundColor API。

2)第二种方式,你可以使用preparecellcolumn api的tableview,它会返回单元格值,然后设置backgroundcolor

+0

我已经细胞的一个实例,因为我使用自定义单元格类。我为图层设置了setBackgroundColor,但不起作用。 –

+0

你是否正在检查单元格内的值? –

+0

Offcourse,打电话给我自己是细胞实例本身:) –