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
votes
4 Answers
0
votes
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