Scrolling background is not transparent in NSScrollView

Scroller

Hello! I am using NSScrollView, which has an NSTableView based view. Whenever a table adds a table cell, scrollers appear, which is normal until you see that scrollers do not have a transparent background. For some reason, this is a white background, as you can see in the image.

I used IB to configure NSScrollView and NSTableView, and I can not find any option where I can turn off the background of the scroller. Any ideas what might be causing this?

Update: settings for my NSScrollView in Xcode

Xcode

+6
source share
4 answers

My only suggestion is to make sure your NSScrollers have a default style or set to a class that overrides + (BOOL)isCompatibleWithOverlayScrollers if you use your own scroller.

In IB, make sure that "Default Style" is selected in the "Scroller Handles" section, second from the top.

enter image description here


OS X Lion introduced the new NSScrollers (overlay scroller), unlike the versions presented in Snow Leopard and before SL (inherited scrollers). Overlay scrollers are a type that fades in / out and draws on top of the content without a bright white background.

In some scenarios, Leo decides to use an outdated scroller instead of new overlay scrollers (because, for example, if a pointer device without a scroll wheel is connected, he cannot precisely scroll through the hidden overlay scroller)

The OS X 10.7 documentation explains this well. To summarize, check if: a) the user has disabled overlay scrollers, b) if you have an unsupported device connected, or c) you subclass NSScroller, add accessories, or forget to override + (BOOL)isCompatibleWithOverlayScrollers .

If you don’t like the legacy scrollers that appear and want to support unsupported devices (for example, a gray scroll bar drawn on top of content that does not fade in / out), you should subclass NSScroller and draw it individually. Applications like Twitter for Mac do it.

+2
source

Override NSScroller and follow these steps. This will give you a transparent background.

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

For me, in my opinion, the controller I set the scroller style, for example:

 [_scrollView setScrollerStyle:NSScrollerStyleOverlay]; 

This made scrollers have a transparent background.

+1
source

If you want to achieve transparency in NSScrollView or just want a clear background for scrolling, just use the setDrawsBackground property for NSScrollView, i.e.:

 [scrollView setDrawsBackground:NO]; 

Hope this helps someone. Thanks:)

-3
source

Source: https://habr.com/ru/post/919285/


All Articles