10
votes

I'm having a problem since Lion introduced elastic scrolling (pictured below). When you scroll my table view (cell-based, with alternating row colors) beyond its bounds, the background doesn't draw. I've tried doing my own drawing in -[drawBackgroundInClipRect:], but it seems like you can't exceed the bounds of the table view. How can I extend the background into elastic scrolling territory?

Scrolling left of table

1
It's the containing NSScrollView that is doing the drawing in this area. Perhaps you can create a pattern for the alternating rows and set that as the background color in the scroll view?Aderstedt
Is this still an issue? I'm unable to reproduce this effect in OS X 10.9.jemmons
@jemmons Not sure I will update once I'm on Mavericks.Dov
If you by chance not planning to use alternating rows and still want to support lion then use cell spacing height to adjust and present a clear distinction between the rows, adjusting these setting will make it look clean and neat.Aneesh Dangayach

1 Answers

0
votes

In Answer to Your Question

A view drawing outside its bounds is generally a no-no. When using alternating background colors, the NSTableView draws its background directly. But in a view-based table view, NSTableRowView is used and if it has its own background color, this is poses even more challenge.

The Bad News

The assemblage of NSScrollView (and its various parts), NSTableView, and NSTableHeaderView is complicated on its own. Once you throw view-based functionality into the mix (where each row has a view and each cell has their own view, and each are reused, animated around, etc.), overriding this behavior "is no way to go through life, son!" ;-)

The Good News

The issue of alternating background colors not extending in an elastically-stretched scrolled table view has been resolved (at least on 10.10, that I can tell), so this is no longer an issue unless you have row/cell views with custom backgrounds or just background colors.

A General Solution For Custom Document (Scrolled) Views

For all other scrolled views with ruled backgrounds you wish to extend for elastic scrolling, you'll need a custom NSScrollView subclass that expects a document view (your custom scrolled view) to conform to a protocol you define (like -(NSImage *)backgroundImageForClipViewBounds:). The scroll view would observe its content view (NSClipView) for bounds change notifications and flag itself for display. When the scroll view's -drawRect: is called, it would then ask the scrolled view for its -backgroundImageForClipViewBounds: (via your protocol) and draw it into itself, thereby making the scrolled view's "infinite background" its own.

I haven't tested this theory but I believe it would work. I hope this helps.