My problem is simple. I used the method of subclassing navigation bar, and then using drawRect to attempt to draw my own custom navigation bar image. However, it doesn’t draw my image… only a blank white space.
The structure of my project is a tab bar with a navigation controller under each one of it’s tabs. Each navigation controller has a navigation bar and I have set those bars to my custom class (customNavBar) in IB.
In my customNavBar.h file I have:
@interface customNavBar : UINavigationBar {
}
@end
In my customNavBar.m file I have:
#import "customNavBar.h"
@implementation customNavBar
-(void) dealloc{
[super dealloc];
}
- (void)drawRect:(CGRect)rect
{
UIImage *image = [UIImage imageNamed:@"navigation_bg.png"];
[image drawInRect:CGRectMake(55, 0, self.frame.size.width, self.frame.size.height)];
}
@end
Any ideas why my image might not be showing and instead just getting a white background? My image is in the project under the resources folder.
Thank you everyone. 🙂
When I implemented your code in a test project, I did in fact see the image. I however did
The image ended up covering the bottom half of the nav bar and the top half was white (like you are seeing). Perhaps your image is being drawn too low? Try playing with the rect values or just set it to self.frame like I did and see what happens. If you still don’t see image, make sure your nav bar class is actual set to your custom class in interface builder and that code is being called to draw your nav bar (maybe put print statement be sure).