Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shanegao/2887220 to your computer and use it in GitHub Desktop.

Select an option

Save shanegao/2887220 to your computer and use it in GitHub Desktop.
uinavigationbar custom background image
//1.
[self.navigationController.navigationBar addSubview:[[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"navbarbg.png"]] autorelease]];
//2.
self.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"navbarbg.png"]];
//3.
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
if([self isMemberOfClass:[UINavigationBar class]]) {
UIImage *image = [UIImage imageNamed:@"navbarbg.png"];
CGContextClip(ctx);
CGContextTranslateCTM(ctx, 0, image.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextDrawImage(ctx,
CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage);
} else {
[super drawLayer:layer inContext:ctx];
}
}
@end
//4. for above iOS 5
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_bg.png"] forBarMetrics:UIBarMetricsDefault];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment