如何让NSTableView透明?

发布于 2024-12-04 10:39:55 字数 572 浏览 2 评论 0原文

我想让 NSTableView 透明。
我在这里使用 WindowController 类。
我正在尝试这样做:

- (void)windowDidLoad
{
     [super windowDidLoad];
     [[self enclosingScrollView] setDrawsBackground: NO];
     [[self enclosingScrollView] setBorderType:NSNoBorder];

}

- (BOOL)isOpaque {

      return NO;
} 
- (void)drawRect:(NSRect)drawRect
{
     [super drawRect: drawRect];
}

但是当我编写这段代码时,我在帮助窗口中找不到 enleadingScrollView
你可以在这里看到..

在此处输入图像描述

有帮助吗?如果我做错了什么,请记住我或纠正我。
谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁把谁当真 2024-12-11 10:39:55

如果您有一个包含 NSTableViewNSScrollView,您可以将滚动视图的 drawsBackground 属性设置为 NO,如下所示:

yourScrollView.drawsBackground = NO;

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

yourScrollView.drawsBackground = NO;

从此见与不见 2024-12-11 10:39:55

得到答案..!!!我刚刚尝试过这个

[tableview setBackgroundColor:[NSColor clearColor]]; 
[tableview setHeaderView:nil]; 

,它工作正常.. – – Snehal

从有问题的评论中复制,因为它有点被埋藏了......

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

岁月蹉跎了容颜 2024-12-11 10:39:55

如果您的应用需要显示透明表格视图,请将表格视图的背景颜色设置为清晰,并将封闭的滚动视图设置为不绘制其背景。以下代码片段显示了显示透明表格的一种方法:

Swift:

yourTableView.backgroundColor = NSColor.clear
yourTableView.enclosingScrollView?.drawsBackground = false

Objective-C

[theTableView setBackgroundColor:[NSColor clearColor];
[[theTableView enclosingScrollView] setDrawsBackground:NO];

Apple - 修改表格的视觉属性

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文