Scroller background not transparent in NSScrollView

余生颓废 提交于 2019-12-03 14:44:41

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

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


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.

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)

The OS X 10.7 documentation explains 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.

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 NSScroller and draw it custom-ly. Applications like Twitter for Mac do this.

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

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

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

[_scrollView setScrollerStyle:NSScrollerStyleOverlay]; 

This made the scrollers have the transparent background.

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

[scrollView setDrawsBackground:NO];

Hope this helps someone. Thanks :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!