Reset the appearance settings for UINavigationBar to the default

advertisements

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


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.