将UINavigationBar的外观设置重置为默认值

时间:2013-05-16 12:48:35

标签: iphone ios objective-c

我一直在使用精彩的[[UINavigationBar appearance] set...为我的UI设置应用程序范围的外观。但是,我正在使用SKStoreProductViewController并希望删除所有样式,以便显示默认的Apple UI。奇怪的是,没有做任何事情,我得到了一个普通的UI和我的自定义用户界面,我真的不明白。我试过反对我所有的UI更改:

    [storeController.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [storeController.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                           nil, UITextAttributeTextColor,
                                                           nil, UITextAttributeTextShadowColor,
                                                           nil]];

    [storeController.navigationController.navigationBar setTitleVerticalPositionAdjustment:0 forBarMetrics:UIBarMetricsDefault];
    [storeController.navigationController.navigationItem.leftBarButtonItem setBackgroundVerticalPositionAdjustment:0 forBarMetrics:UIBarMetricsDefault];

但这似乎不起作用,根本没有任何区别。如何将其重新设置为默认的UI设置?

问候,
麦克

2 个答案:

答案 0 :(得分:7)

好的,我不得不求助于一个讨厌的小解决方法来解决这个问题。虽然我一直都知道这是一种做法,但我不想诉诸它,因为它感觉很乱。

我将UINavigationController子类化为类似CustomNavigationViewController的内容,并且完全没有对其进行任何更改。换句话说,它是UINavigationController,但名称不同。然后我用了:

[[UINavigationBar appearanceWhenContainedIn:[CustomNavigationViewController class], nil] set.... 设置外观,仅将其应用于我的自定义类的NavigationControllers。 SKStoreProductViewController显然不属于我的自定义类,因此无法获得样式。

在我看来,这是一个讨厌的,不洁净的修复,但它确实有效。

麦克

答案 1 :(得分:0)

通过使用UIAppearance代理,您可以非常具体地了解这些项目的样式。 这个方法只有当它包含在特定的视图控制器类中时才应用样式。

有一个很好的教程here

相关问题