Ios7 如何使用UIappearance在根viewcontroller中获取透明导航栏

Ios7 如何使用UIappearance在根viewcontroller中获取透明导航栏,ios7,uinavigationbar,uiappearance,Ios7,Uinavigationbar,Uiappearance,在我的应用程序的委托中,我指定了一个透明的工具栏(如问题18969248的答案所示):- 代码是: UINavigationBar *navigationBarAppearance = [UINavigationBar appearance]; navigationBarAppearance.backgroundColor = [UIColor clearColor]; [navigationBarAppearance setBackgroundImage:[[UIImage alloc] in

在我的应用程序的委托中,我指定了一个透明的工具栏(如问题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加载)。
如何在根视图控制器的导航栏中获得透明度?

如果您使用的是故事板,可能应该通过AppDelegate以编程方式加载根视图控制器:

- (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];

}