4
votes

I am trying to recreate a bit of functionality that can be seen in Apples Calendar app (osx) with an NSScrollView. When you scroll up and down past the bounds of the view in the Calendar app it isn't just a blank space, but it extends the grid lines from the calendar itself. I was wondering how this can be done? I'm hoping there answer will be pretty simple. Something like drawing the content view bigger than needs be and then setting some property on the scroll view to constrain what it considers to be the scrollable content. After pouring over the NSScrollView documentation I have yet to find any leads. Forgive me if the answer is relatively simple and thank you for any answers.

4

4 Answers

0
votes

Its pretty much as the NSScrollView documentation says. Use:

-(void)setDocumentView:(NSView *)aView

Set an NSClipView on it. This holds the drawn content which is larger than the displayed portion and will scroll parts not visible into view. You should also take a look at the "Cocoa Drawing Guide".

0
votes

This was adopted from someone else's code here on Stackoverflow. This code draws horizontal grid past the top of the table. I suppose you can change it to draw vertical grid as well. Put it in your NSTableView subclass:

- (void)drawGridInClipRect:(NSRect)clipRect
{
    NSRect boundsToDraw = clipRect;
    CGFloat   yStart   = 0;

    if ( clipRect.origin.y < 0 ) {

        while (yStart > NSMinY(boundsToDraw)) {

            CGFloat yRowTop = yStart - self.rowHeight;

            NSRect rowFrame = NSMakeRect(0, yRowTop, boundsToDraw.size.width, 1.0);

            [[self gridColor] set];

            NSRectFill(rowFrame);

            yStart -= self.rowHeight;

        }
    }
}
0
votes

set the background of the scrollView to draw the right background... that would duplicate calendars effect as there is no dynamic content

0
votes

You can draw outside of the document view with a semi-private method:

- (void)drawBackgroundOverhangInRect:(NSRect)dirtyRect {
    [[NSColor cyanColor] set];
    NSRectFill(dirtyRect);
}

Available after 10.7