views:

40

answers:

1

Hi,

I'm trying to set a background image of an NSView. (Actually an NSScrollView.) At the moment I'm subclassing drawRect: and I'm using NSDrawThreePartImage to draw the image but there are a few things that are not correct whenever I start scrolling. Here's an image. Are there better ways to draw the images?

- (void)drawRect: (NSRect)dirtyRect
{
    dirtyRect.size.height -= 18; //Moving the image up a bit for future subclassing of NSScroller.
    NSDrawThreePartImage(dirtyRect, viewLeftCap, viewFill, viewRightCap, NO, NSCompositeSourceOver, 1, YES);
}
+1  A: 

If you want to redraw the whole view, you should be using [self bounds], not the rect passed into your -drawRect: method.

Joshua Nozzi
Yes, that's it! Thanks a million!
Jane
Specifically, Jane, the `dirtyRect` is just that: The rectangle that's dirty. “Dirty” means in need of updating; in this case, in need of redrawing. It is the section of your view's bounds that you need to redraw. You can draw more, but should not draw any less. (Drawing more than the dirty rect is discouraged for performance reasons, but it's otherwise harmless and sometimes unavoidable. I suggest clipping to the dirty rect when you have no other way to not draw outside it, as in this case.)
Peter Hosey
Thanks for the insight on this.
Jane