问题
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
回答1:
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.
回答2:
Override NSScroller and do the following. This will give you a transparent background.
- (void) drawRect: (NSRect) dirtyRect
{
[self drawKnob];
}
回答3:
For me, in my view controller I set the scroller style like:
[_scrollView setScrollerStyle:NSScrollerStyleOverlay];
This made the scrollers have the transparent background.
回答4:
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 :)
来源:https://stackoverflow.com/questions/11253949/scroller-background-not-transparent-in-nsscrollview