首页 文章

如何使用UIappearance在根视图控制器中获取透明导航栏

提问于
浏览
0

在我的应用程序代表中,我指定了一个透明工具栏(如问题18969248的答案中所建议的): -
代码是:

UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
navigationBarAppearance.backgroundColor = [UIColor clearColor];
[navigationBarAppearance setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
navigationBarAppearance.shadowImage = [[UIImage alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

这适用于推送到导航控制器堆栈的所有视图控制器,但不适用于根视图控制器(从NIB加载) . 如何在根视图控制器的导航栏中获得透明度?

1 回答

  • 0

    如果您使用的是故事板,也许您应该以这种方式通过AppDelegate以编程方式加载RootViewController:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"yourStoryboard"
                                                                 bundle: nil];
        YourCustomRootViewController *customRootVC = (YourCustomRootViewController*) [mainStoryboard instantiateViewControllerWithIdentifier:@"firstAddProductViewController"];
    
        // If you're not using storyboard, simply instantiate it this way
        YourCustomRootViewController *customRootVC = [[YourCustomRootViewController alloc] initWithNibName:@"yourNib" bundle:nil];
    
        /* In here, you want to add the code relative to the navigation bar of your rootVC */
        [self.window setRootViewController:customRootVC];
    
    }
    

相关问题