Skip to content

Instantly share code, notes, and snippets.

@sco
Created March 4, 2009 01:53
Show Gist options
  • Save sco/73661 to your computer and use it in GitHub Desktop.
Save sco/73661 to your computer and use it in GitHub Desktop.
@interface CustomNavigationBar : UINavigationBar {
UIImageView *backgroundView;
}
@end
@implementation CustomNavigationBar
- (void)setBackgroundImage:(UIImage*)image {
if(image == NULL){
return;
}
UIImageView *bgView = [[UIImageView alloc]initWithImage:image];
backgroundView = bgView;
[self addSubview:backgroundView];
[self sendSubviewToBack:backgroundView];
[bgView release];
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
[self setBackgroundImage:[UIImage imageNamed:@"navbackground.png"]];
}
return self;
}
- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated {
[super pushNavigationItem:item animated:animated];
[self sendSubviewToBack:backgroundView];
}
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated {
[super popNavigationItemAnimated:YES];
[self sendSubviewToBack:backgroundView];
return [self topItem];
}
- (void)dealloc {
[backgroundView release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment