在UITabBarController中的“更多”视图控制器的自定义导航栏

使用下面的代码(适用于较低版本的iOS),我将UINavigationBar并应用到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 

该代码可以正常工作的视图控制器是明显可访问的,但是当按“更多”选项卡访问其他视图控制器,自定义图像不会再出现。 我错过了什么吗?

我自定义更多视图控制器的方式是确保你不会从UITabBarController本身获得更多的控制器 – 这听起来像你正在经历的。

1创build您自己的更多视图控制器。 它将有自己的自定义图标

 //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; } 

接着

2当你初始化你的UITabBarController时,确保你发送五个完全视图控制器到初始化程序,并且你自定义的更多的视图控制器是第五项的根视图控制器 – 也就是说,通常你会使用一个导航控制器,它是rootViewController。

UITabBarController将为More项目创buildUINavigationController ,所以它的UINavigationBar不会是你的类的一个实例,而是一个UINavigationBar

你可以看看iOS 5的外观API来改变它的外观和感觉。

你可以使用tabBarController的moreViewController属性来获得更多的导航控制器(我在iOS7上使用这个应用程序)

  UINavigationController *moreViewController = tabController.moreNavigationController; if(moreViewController) { [moreViewController.navigationBar setBarTintColor: [UIColor yellowColor]]; [moreViewController.navigationBar setTintColor: [UIColor whiteColor]]; }