How to make NSTableView transparent?
Asked Answered
L

3

13

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..

enter image description here

Any help?? Please remember me or correct me if i am doing something wrong.
Thank you.

Longs answered 15/9, 2011 at 6:37 Comment(2)
Got Answer..!!! I just tried this [tableview setBackgroundColor:[NSColor clearColor]]; [tableview setHeaderView:nil]; and its working fine..Longs
this worked for me as well. specifically setting the background color to a clearColorSears
N
7

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...

Nutwood answered 24/6, 2015 at 17:24 Comment(0)
D
8

If you have an NSScrollView enclosing your NSTableView, you can set the scroll view's drawsBackground property to NO like this:

yourScrollView.drawsBackground = NO;

Dena answered 9/1, 2014 at 14:54 Comment(0)
N
7

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...

Nutwood answered 24/6, 2015 at 17:24 Comment(0)
M
5

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

Methodism answered 4/12, 2017 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.