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

- by

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.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.