Reputation: 3411
I'm currently doing the following:
BlogViewController *viewController = [[BlogViewController alloc] initWithBlogPosts];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self presentModalViewController:navController animated:YES];
[viewController release];
[navController release];
However, I need a way to use a custom UINavigationBar. I've tried using a category like this:
@implementation UINavigationBar (Image)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"toolbar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
But it doesn't seem to pick that up. Any suggestions? BlogViewController is a subclass of UIViewController.
Upvotes: 1
Views: 234
Reputation: 19800
I used this guy's answer:
[self.navigationController setValue:[[[CustomNavBar alloc]init] autorelease] forKeyPath:@"navigationBar"];
Upvotes: 0
Reputation: 119292
For ios5, you can set the background image directly using setBackgroundImage:forBarMetrics:
.
Leave the category implementation around for pre-ios5, and check that the navigation bar responds to the selector above, and you've covered both versions.
Upvotes: 1
Reputation: 933
I had a similar problem a while ago and then learned that you can actually do this on your app delegate:
After the #import... and before the implementation of the actual appDelegate.
Don't know if it helps but could be a good start point.
@implementation UINavigationBar (Background)
-(void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"myNavBar.png"];
[image drawInRect:CGRectMake(0,0,self.frame.size.width, self.frame.size.height)];
}
@end
@implementation AppDelegate // code for appDelegate
Upvotes: 0