针对“更多"的自定义导航栏UITabBarController中的视图控制器 [英] Custom navigation bar for the "More" View Controller in a UITabBarController
问题描述
使用以下代码(适用于iOS的较低版本),我将 UINavigationBar
子类化,并应用于 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
.
@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?
推荐答案
我自定义更多视图控制器"的方法是确保您不会从UITabBarController本身获取默认的更多"控制器-这听起来像是您自己体验.
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创建您自己的更多"视图控制器.它将具有自己的自定义图标
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;
}
然后
2初始化UITabBarController时,请确保将五个完全视图控制器发送到初始化程序,并确保您的自定义更多视图控制器是第5个项目的根视图控制器-即通常您会使用导航控制器,并将您的更多视图控制器设置为rootViewController.
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.
这篇关于针对“更多"的自定义导航栏UITabBarController中的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!