Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset appearance settings for UINavigationBar back to default

I've been using the fantastic [[UINavigationBar appearance] set... to set application wide appearances for my UI. However, I'm using the SKStoreProductViewController and want to remove all of my styling so that it shows the default Apple UI. Weirdly, without doing anything, I get a mish mash of normal UI and my custom UI, which I don't really understand. I've tried countering all my UI changes like this:

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

But that doesn't seem to work, making no difference at all. How can I set it back to the default UI settings?

Regards,
Mike

like image 707
Mackey18 Avatar asked May 16 '13 12:05

Mackey18


People also ask

How do I set the default navigation bar?

Click Settings > All Settings in the menu bar. In the User Accounts grouping, click Manage Accounts. Select a user, and click Edit. Scroll down to Default Menu Bars and Views, and select top menu bars from the lists.

How do I change the navigation bar on my Iphone?

In the Safari app , you can choose the layout that works best for you. Depending on the layout, the search field appears at the top (Single Tab layout) or bottom (Tab Bar layout) of the screen. Go to Settings > Safari, then scroll down to Tabs. Select either Tab Bar or Single Tab.


1 Answers

Ok then, I've had to resort to a nasty little workaround to fix this issue. While I always knew that this would be one way of doing it, I didn't want to have to resort to it because it feels messy.

I subclassed UINavigationController to something like CustomNavigationViewController and made absolutely no changes to it. So in other words, it IS UINavigationController but with a different name. I then used:

[[UINavigationBar appearanceWhenContainedIn:[CustomNavigationViewController class], nil] set.... to set the appearance, applying it only to those NavigationControllers that are of my custom class. The SKStoreProductViewController obviously isn't of my custom class, and therefore doesn't get the styling for it.

This is a nasty, unclean fix in my opinion, but it works.

Mike.

like image 163
Mackey18 Avatar answered Sep 30 '22 14:09

Mackey18