[英]Custom navigation bar for the “More” View Controller in a UITabBarController
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
. 使用下面的代码(适用于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
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?
我错过了什么吗?
You can use the moreViewController property of your tabBarController to get the more Navigation Controller (I used this on iOS7 app) 您可以使用tabBarController的moreViewController属性来获取更多的Navigation Controller(我在iOS7应用中使用过此控件)
UINavigationController *moreViewController = tabController.moreNavigationController;
if(moreViewController)
{
[moreViewController.navigationBar setBarTintColor: [UIColor yellowColor]];
[moreViewController.navigationBar setTintColor: [UIColor whiteColor]];
}
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. UITabBarController
将为More项目创建UINavigationController
,因此其UINavigationBar
不会是您的类的实例,而是UINavigationBar
。
You can look at the iOS 5 appearance API to change the look and feel with it. 您可以查看iOS 5外观API来更改其外观。
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. 我自定义“更多视图控制器”的方式是确保您不会从UITabBarController本身获取默认的“更多”控制器-听起来像您正在体验的那样。
1 Create your own More view controller. 1创建自己的“更多”视图控制器。 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 - ie commonly you would use a navigation controller with your more view controller being set to it's rootViewController. 2初始化UITabBarController时,请确保将五个完全相同的视图控制器发送给初始化程序,并确保您的自定义more view controller是第5项的根视图控制器-即,通常,您将使用导航控制器,并将more view controller设置为它是rootViewController。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.