I've managed to add a custom background to my navigation bar by using:
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"UINavigationBar.png"]];
[myViewController.navigationBar insertSubview:iv atIndex:0];
[iv release];
This works fine and I can see the title and buttons okay. However, when I drill down one level and then go back to the root, the buttons are hidden, but the title is still visible. It appears the navigation bar image is covering the button items.
I'm confused as I'm inserting it at the bottom so I would assume when the navigation items are pushed and popped that they are displayed above other views in the navigation bar.
Any ideas?
Thanks,
Mike
NavigationBar's subviews are constantly changing, i mean every view appear/disappear, so you shouldn't expect to have the added imageview at the index 0 of the subviews array.
You could try to add this at viewDidAppear (in every viewcontroller that manage navigation items /:):
I have used Hauek's solution but when the bar has diferent flavor in other controllers, it could give some minor problems, anyway, this is neither the best option.
Hope it help, at least to understand why what you were doing wasn't working,
The way you can simply add a new background to your UINavigationBar is next.
Instead of doing it in drawRect: you can override the drawLayer:inContext: method in a UINavigationBar category class. Inside the drawLayer:inContext: method, you can draw the background image you want to use. Also you can choose different images for portrait and landscape interface orientations if your app supports multiple interface orientations.
This complete demo Xcode project on customizing the appearance of UINavigationBar might also be helpful.
Following the description from here, I suggest adding a category to the nav bar.
On iOS 5 this will not work but the good news is that there is a simple way of doing this
NOTE: This will only work on iOS 5 and above so make sure you check iOS version if you want to be backwards compatible.