Reputation: 1075
I want to make transparent NSTableView.
I am using WindowController class here.
I was trying this:
- (void)windowDidLoad
{
[super windowDidLoad];
[[self enclosingScrollView] setDrawsBackground: NO];
[[self enclosingScrollView] setBorderType:NSNoBorder];
}
- (BOOL)isOpaque {
return NO;
}
- (void)drawRect:(NSRect)drawRect
{
[super drawRect: drawRect];
}
But when i was writing this code i can't found enclosingScrollView
in help window.
you can see here..
Any help?? Please remember me or correct me if i am doing something wrong.
Thank you.
Upvotes: 13
Views: 5262
Reputation: 13429
If your app needs to display a transparent table view, set the background color of the table view to be clear and set the enclosing scroll view to not draw its background. The following code snippet shows one way to display a transparent table:
Swift:
yourTableView.backgroundColor = NSColor.clear
yourTableView.enclosingScrollView?.drawsBackground = false
Objective-C
[theTableView setBackgroundColor:[NSColor clearColor];
[[theTableView enclosingScrollView] setDrawsBackground:NO];
Apple - Modifying a Table’s Visual Attributes
Upvotes: 5
Reputation: 7200
Got Answer..!!! I just tried this
[tableview setBackgroundColor:[NSColor clearColor]];
[tableview setHeaderView:nil];
and its working fine.. – – Snehal
Copied from comment in question, as its a bit buried...
Upvotes: 7
Reputation: 12820
If you have an NSScrollView
enclosing your NSTableView
, you can set the scroll view's drawsBackground
property to NO
like this:
yourScrollView.drawsBackground = NO;
Upvotes: 8