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

时间:2014-03-07 10:10:48

标签: ios7 uinavigationbar uiappearance

在我的应用代表中,我指定了一个透明工具栏(如问题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 :(得分: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];

}