Skip to content

Instantly share code, notes, and snippets.

@densa
Created June 15, 2011 11:58
Show Gist options
  • Save densa/1026937 to your computer and use it in GitHub Desktop.
Save densa/1026937 to your computer and use it in GitHub Desktop.
Custom background for UIToolbar w/ UINavigationBar
@interface UIToolbar (CustomImage)
@end
#import "UIToolbar+CustomBackground.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIToolbar (CustomImage)
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
[super drawLayer:layer inContext:ctx];
if (self.barStyle == UIBarStyleBlackOpaque) {
CALayer *imgLayer = [[CALayer alloc] init];
[imgLayer setContents:(id)[[UIImage imageNamed: @"toolbar.png"] CGImage]];
[imgLayer setBounds:CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height)];
[imgLayer setPosition:CGPointMake(self.bounds.size.width/2,self.bounds.size.height/2)];
[layer insertSublayer:imgLayer atIndex:0];
[imgLayer release];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment