Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroller background not transparent in NSScrollView

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.

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?

Update: Settings for my NSScrollView in Xcode

Xcode

like image 304
iMaddin Avatar asked Jun 28 '12 22:06

iMaddin


2 Answers

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

- (void) drawRect: (NSRect) dirtyRect
{
    [self drawKnob];
}
like image 65
David Avatar answered Oct 21 '22 03:10

David


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.

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.

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.

like image 37
Vervious Avatar answered Oct 21 '22 05:10

Vervious