简体   繁体   English

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

[英]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.

相关问题 UITabBarController的子视图控制器中的导航栏按钮无响应 - Navigation bar button unresponsive in child view controller of UITabBarController 在SWIFT 3中访问UITabBarController的“更多…”视图控制器 - Access the 'More…' View Controller of UITabBarController in SWIFT 3 如何更改UITabBarController的'更多'视图控制器tintColor? - How to change 'More' view controller tintColor of UITabBarController? 自定义导航控制器和导航栏? - Custom navigation controller and navigation bar? 从嵌套在UITabBarController中的导航控制器中推送视图控制器? - Pushing a View Controller from a Navigation Controller nested in a UITabBarController? UITabBarController在“更多导航控制器”中暂时缺少项目标题和图像 - UITabBarController temporarily missing item title and image in More Navigation Controller iOS 以编程方式创建的 UITabBarController 不显示其“更多”导航 controller - iOS UITabBarController created programmatically is not displaying its “More” navigation controller 自定义视图控制器演示导致导航栏反弹 - Custom view controller presentation causes the navigation bar to bounce 通过自定义过渡导航栏推送视图控制器时不会设置动画 - On pushing a view controller through custom transition navigation bar does not animate iOS 7中的UITabbarController布局问题 - 视图位于导航栏后面 - UITabbarController layout issues in iOS 7 - view going behind the navigation bar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM