Mackey18
Mackey18

Reputation: 2352

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

Upvotes: 7

Views: 5206

Answers (2)

Mackey18
Mackey18

Reputation: 2352

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.

Upvotes: 9

Cocoadelica
Cocoadelica

Reputation: 3026

You can be quite specific about styling these items by using the UIAppearance proxy. THis has a method that applies the styling only when it's contained in a specific view controller class.

There's a good tutorial here:

Upvotes: 0

Related Questions