xcode NSScrollView 中的滚动背景不透明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11253949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:43:53  来源:igfitidea点击:

Scroller background not transparent in NSScrollView

objective-cxcodensscrollviewscroller

提问by iMaddin

Scroller

滚动条

Hi! I am using an NSScrollView which has a view-based NSTableView. Whenever the table adds a table cell the scrollers show up which is fine until you see that the scrollers don't have a transparent background. For some reason it's background is white as you can see on the image.

你好!我正在使用具有基于视图的 NSTableView 的 NSScrollView。每当表格添加表格单元格时,滚动条就会显示出来,这很好,直到您看到滚动条没有透明背景。出于某种原因,它的背景是白色的,正如您在图像上看到的那样。

I used IB to set up the NSScrollView and NSTableView and I cannot find any option where I can disable the scroller's background. Any ideas what may have cause this?

我使用 IB 来设置 NSScrollView 和 NSTableView,但找不到任何可以禁用滚动条背景的选项。任何想法可能导致这种情况?

Update: Settings for my NSScrollView in Xcode

更新:Xcode 中我的 NSScrollView 的设置

Xcode

Xcode

采纳答案by Vervious

My only suggestion is to make sure that your NSScrollersare of the default style, or set to a class that overrides + (BOOL)isCompatibleWithOverlayScrollersif you are using a custom scroller.

我唯一的建议是确保您NSScrollers是默认样式,或者+ (BOOL)isCompatibleWithOverlayScrollers如果您使用自定义滚动条,则设置为覆盖的类。

In IB, check that "Default Style" is selected under "Scroller Knobs", second from the top.

在 IB 中,检查是否在“Scroller Knobs”下选择了“Default Style”,从顶部倒数第二个。

enter image description here

在此处输入图片说明



OS X Lion introduced the new NSScrollers(overlay scrollers) in contrast to the versions present in Snow Leopard and before SL (legacy scrollers). The overlay scrollers are the type that fade in/out, and draw on top of the content without the glaring white background.

NSScrollers与 Snow Leopard 和 SL 之前的版本(传统卷轴)相比,OS X Lion 引入了新的(覆盖卷轴)。覆盖滚动条是淡入/淡出的类型,并在没有耀眼的白色背景的情况下绘制在内容之上。

In some scenarios Lion decides to use the legacy scroller instead of the new overlay scrollers (because, e.g., if a pointer device w/o scroll wheel is plugged in, it can't exactly scroll a hidden overlay scroller)

在某些情况下,Lion 决定使用旧滚动条而不是新的覆盖滚动条(因为,例如,如果插入了不带滚轮的指针设备,则它无法准确滚动隐藏的覆盖滚动条)

The OS X 10.7 documentationexplains it well. To summarize, check if a) the user disabled overlay scrollers, b) if you have an unsupported device plugged in, or c) you're subclassing NSScroller, adding accessory views, or forgetting to override + (BOOL)isCompatibleWithOverlayScrollers.

OS X 10.7 文档很好地解释了它。总而言之,请检查 a) 用户是否禁用了覆盖滚动条,b) 是否插入了不受支持的设备,或者 c) 您正在继承 NSScroller、添加附件视图或忘记覆盖+ (BOOL)isCompatibleWithOverlayScrollers.

If you dislike the legacy scrollers showing up and want to support non-supported devices (e.g. a gray scrollbar drawn on top of content that doesn't fade in/out) you must subclass NSScrollerand draw it custom-ly. Applications like Twitter for Mac do this.

如果您不喜欢显示的旧滚动条并希望支持不受支持的设备(例如,在不淡入/淡出的内容顶部绘制的灰色滚动条),您必须子类化NSScroller并自定义绘制它。像 Twitter for Mac 这样的应用程序可以做到这一点。

回答by David

Override NSScroller and do the following. This will give you a transparent background.

覆盖 NSScroller 并执行以下操作。这会给你一个透明的背景。

- (void) drawRect: (NSRect) dirtyRect
{
    [self drawKnob];
}

回答by Chris Livdahl

For me, in my view controller I set the scroller style like:

对我来说,在我的视图控制器中,我将滚动样式设置为:

[_scrollView setScrollerStyle:NSScrollerStyleOverlay]; 

This made the scrollers have the transparent background.

这使滚动条具有透明背景。

回答by Eshwar Chaitanya

If you want to achieve transparency in NSScrollView or simply want a clear background for scroll view...just make use of setDrawsBackgroundproperty of NSScrollView,i.e.:

如果你想在 NSScrollView 中实现透明度或者只是想要一个清晰的滚动视图背景......只需使用setDrawsBackgroundNSScrollView的属性,即:

[scrollView setDrawsBackground:NO];

Hope this helps someone. Thanks :)

希望这可以帮助某人。谢谢 :)