With the code below (for lower versions of iOS) I am subclassing UINavigationBar
and applying to each navigation bar (of each navigation controller) in my UITabBarController
.
@implementation CustomNavigationBar
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"customNavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
The code works fine for the view controllers that are visibly accessible, but when pressing the "More" tab to access the other view controllers, the custom image does not appear any more. Have I missed something?
The way I customise the More View Controller is to ensure that you don't get the default more controller from the UITabBarController itself - which is what sounds like you are experiencing.
1 Create your own More view controller. It will have its own custom icon
//MyMoreViewController.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.title = NSLocalizedString(@"More", @"More");
self.tabBarItem.image = [UIImage imageNamed:@"MyCustomMoreImage"];
}
return self;
}
and then
2 When you initialise your UITabBarController, ensure you send five exactly view controllers to the initialiser AND that your custom more view controller is the root view controller of the 5th item - i.e. commonly you would use a navigation controller with your more view controller being set to it's rootViewController.
The UITabBarController
will create the UINavigationController
for the More item, so its UINavigationBar
won't be an instance of your class, but a UINavigationBar
instead.
You can look at the iOS 5 appearance API to change the look and feel with it.
You can use the moreViewController property of your tabBarController to get the more Navigation Controller (I used this on iOS7 app)
UINavigationController *moreViewController = tabController.moreNavigationController;
if(moreViewController)
{
[moreViewController.navigationBar setBarTintColor: [UIColor yellowColor]];
[moreViewController.navigationBar setTintColor: [UIColor whiteColor]];
}