Skip to content

Instantly share code, notes, and snippets.

@rainerborene
Created December 27, 2010 17:25
Show Gist options
  • Save rainerborene/756317 to your computer and use it in GitHub Desktop.
Save rainerborene/756317 to your computer and use it in GitHub Desktop.
Custom Toolbar Background
#import "ViewBackground.h"
@implementation ViewBackground
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
// Create a new image and make it as big as the view
NSImage* bg = [[NSImage alloc] initWithSize:[self bounds].size];
// Prepare for drawing onto the new image
[bg lockFocus];
NSImage* toolbarImage = [NSImage imageNamed:@"ToolbarBackground.png"];
NSColor* backgroundColor = [NSColor colorWithPatternImage:toolbarImage];
[backgroundColor set];
NSRectFill([self bounds]);
[bg unlockFocus];
// Now draw the image to the view
[bg drawInRect:[self bounds]
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0f];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment