Andy
Andy

Reputation: 479

Status Bar Background Color with Translucent Navigation Bar

So I am bashing my head over what seems to be a simple problem...

I am trying to make it such that my status bar in my app has a background color. Now the issue I am having is that I have :

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

Which means the text will be white. That is great, but the issue comes when I run the app and use it. I have A navigation controller (with a tableview) embedded in a tab bar controller so that when you scroll down the header disappears. Think similar functionality to Facbook, LinkedIn ect.

So now what happens is when I scroll the status bar is translucent with white text... therefore unreadable.

So I figured I could add a subview as follows :

UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20);
addStatusBar.backgroundColor = [UIColor orangeColor];
[self.window.rootViewController.view addSubview:addStatusBar];

This seemed to work but the color isn't right... so I had to turn translucent property off my navigation bar :

self.navigationController.navigationBar.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
self.navigationController.navigationBar.translucent = NO;

Which means now the color stays but it isn't right, and when I scroll you can tell there is a view on top instead of the text from the nav bar "Fading" into the top (as Facebook, and LinkedIn)

What am I missing here? Is there no way to access the statusBar.backgroundColor??

Thanks for your help.

A

Upvotes: 0

Views: 1308

Answers (1)

Chandu
Chandu

Reputation: 82

You won't find “UIViewControllerBasedStatusBarAppearance” property in your plist but by default its not there. You have to add it by yourself by clicking on the + button and then set it to “NO”.

After Adding to .plist, you have to go to your AppDelegate.m file and add the following in didFinishLaunchingWithOptions method, add the following lines of code:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    UIView *addStatusBar = [[UIView alloc] init];
    addStatusBar.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20);
    addStatusBar.backgroundColor = [UIColor orangeColor];

YourViewController *vc = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@“YourViewController"];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc];

self.window.rootViewController = tabBarControllerObj;
[self.window.rootViewController.view addSubview:addStatusBar];

I hope this helps for you.

Upvotes: 1

Related Questions