Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coloured Status Bar on a TabBarController with NavigationBar not working

I've read a lot of posts on here and tried most of the options mentioned, but none fix the issue for me. I have an app that is based off of a Tab Bar Controller. Each tab is a UIViewController with a Navigation Bar at the top.

Adding this code to the AppDelegate gives me an orange coloured Navigation Bar with white text, but a white status bar with Black text.

[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

Reading the answers on various pages suggest adding the following to the View controller:

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

Then calling this in View Did Load:

[self setNeedsStatusBarAppearanceUpdate];

This gets me a White status bar with White text, how can I now get the status bar to go orange to match my Navigation Bar??

The solution mentioned on here https://stackoverflow.com/a/19513714/505457 for those using a Navigation Controller doesn't work, I guess thats because my main controller is a Tab Bar Controller.

Anyone come across this before? Thanks in advance for any advice / suggestions you may have. I can provide a sample app if required, but its probably as quick to build one with the Tab Bar template, add a Navigation bar then paste in my code samples.

Plasma

like image 220
Plasma Avatar asked May 03 '16 21:05

Plasma


2 Answers

You can find the statusBar UIVIew by it's name and tint it. Add this method to your AppDelegate.m and call it from didFinishLaunchingWithOptions:

- (void)setStatusBarBackgroundColor:(UIColor *)color {

    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 ...   

    [self setStatusBarBackgroundColor:[UIColor orangeColor]];

 ...

}

Note: There are apps in store that use this method. So it is okay with the apple HIG policy.

like image 189
Pau Senabre Avatar answered Oct 04 '22 17:10

Pau Senabre


Well I had almost the same problem since IOS7 , But my quick solution is to change all your views from the first one, I am refering to set up your color bar configuration in the AppDelegate.m file, I recommend to use this free framework Nab Bar Color And Gradient is very easy to use and also you will be available to set a beautiful gradient on all of your views.

See the examples in the project.

like image 25
Gerardo E Martínez Avatar answered Oct 04 '22 16:10

Gerardo E Martínez