Skip to content

Instantly share code, notes, and snippets.

@nicklockwood
Created January 23, 2012 10:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicklockwood/1662427 to your computer and use it in GitHub Desktop.
Save nicklockwood/1662427 to your computer and use it in GitHub Desktop.
Customise UINavigationBar background on iOS 4 & 5
@implementation UINavigationBar (CustomBackground)
- (UIImage *)barBackground
{
return [UIImage imageNamed:@"top-navigation-bar.png"];
}
- (void)didMoveToSuperview
{
//iOS5 only
if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
[self setBackgroundImage:[self barBackground] forBarMetrics:UIBarMetricsDefault];
}
}
//this doesn't work on iOS5 but is needed for iOS4 and earlier
- (void)drawRect:(CGRect)rect
{
//draw image
[[self barBackground] drawInRect:rect];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment