How to turn the Navigation Bar in iOS 6 opaque when compiling with Xcode 5

Xcode 5 is nice… but it has habits that drive me up the wall. For example, no matter which Base SDK you compile with, your Navigation Bars will always look translucent – no matter how hard you try to avoid this in the Storyboard, and no matter which iOS Version you deploy to.

Would have never happened under Xcode 4. But I suppose we must go with the times.

All we can do is to turn it opaque in code – and if we’re not using black, at least give iOS 7 a tint of your selected colour at the same time. This method will take a UINavigationController and change its colour:

- (void)navBarColour:(UINavigationController *)navController {
    
    if ([navController.navigationBar respondsToSelector:@selector(barTintColor)]) {
        
        // we're running iOS 7
        navController.navigationBar.barTintColor = [UIColor blackColor];
        
    } else {
        
        // we're on iOS 6 and before
        navController.navigationBar.tintColor = [UIColor blackColor];
    }
}

Note that on iOS 7 your navigation bars are always translucent, I haven’t found a way to change this. All you can do is “tint” those. The above code will however bring opaqueness back into your apps when running on iOS 6.





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.