Created
December 27, 2010 17:25
-
-
Save rainerborene/756317 to your computer and use it in GitHub Desktop.
Custom Toolbar Background
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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