1

Hi I am developing small IOS application in which I am using simple one window with navigation controller. What I want to do is change status bar colour to white. For that I did following things.

[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

It works fine.enter image description here

But now I don't want navigation bar and I hide it self.navigationController.navigationBarHidden = YES;

It removes navigation bar but it is not applying that white colour theme to my status bar. It again turn to black.

enter image description here

I don't want navigation bar but I want to change status bar content to white. How to do this. Need Help. Thank you.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
nilkash
  • 7,408
  • 32
  • 99
  • 176

4 Answers4

3

Use UIStatusBarStyleLightContent.

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];

Also, change the UIViewControllerBasedStatusBarAppearance in your PLIST file to NO.

NOTE: This question has been asked before. Please research a little more for questions like this.

Community
  • 1
  • 1
n00bProgrammer
  • 4,261
  • 3
  • 32
  • 60
  • Thank you sir for your quick replay. this solution is not working for me. Because I am hiding navigation bar. If I have navigation bar visible then it works fine. But if i hide it then its not working. Need Help. Thank you. – nilkash Apr 28 '14 at 10:08
  • In Plist file I put UIViewControllerBasedStatusBarAppearance to NO and in appdelegate file I put above code – nilkash Apr 28 '14 at 10:20
  • My show navigation bar property is uncheck in storyboard. Because I don't want navigation bar. – nilkash Apr 28 '14 at 10:24
  • This is peculiar. What color is the status bar text in your case ? – n00bProgrammer Apr 29 '14 at 05:10
  • 1
    Add it in the first view controller of your application's `viewWillAppear`, instead of appDelegate. Try this and tell if it's working. – n00bProgrammer Apr 29 '14 at 05:11
  • But I tried It in another project its not working for that one. I set Plist attribute. Then I set all the values like I said before. But still showing same problem. It's works for another project. Am I doing some thing wrong. – nilkash Apr 29 '14 at 05:44
1

you can set a UIView with color on status bar, check this:

UIView *temporaryStatusBar = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] statusBarFrame]];
temporaryStatusBar.backgroundColor = [UIColor greenColor];
[self.window addSubview:temporaryStatusBar];
M.Alatrash
  • 1,270
  • 1
  • 12
  • 30
  • I tried It. It will change only background colour for status bar but will not change text colour to white. – nilkash Apr 28 '14 at 11:13
  • for the text color you need to change the status bar style to UIStatusBarStyleLightContent this style will give u a white color text – M.Alatrash Apr 28 '14 at 11:14
  • Yeah i tried that as well It working fine if my navigation bar is not hidden. But If hide navigation bar then it will not work. Please read question carefully. – nilkash Apr 28 '14 at 11:16
  • i just edited the answer, u can check it now and it's working cause i tested this code also while the navigationBar is hidden :) – M.Alatrash Apr 28 '14 at 11:23
  • this is my code, u can add this code in the AppDelegate after the didFinishLunching or u can use it in your RootViewController in the viewDidLoad!! where do use this code? and what's not working for u, the text color or the status bar color ??? – M.Alatrash Apr 28 '14 at 12:10
  • I put this code in Appdelegate didFinishLaunch method. and It is not reflecting any thing. :( – nilkash Apr 28 '14 at 12:22
  • and what's not working for you? the text color of the status bar or the UIView not showing ?? – M.Alatrash Apr 28 '14 at 12:47
  • I want to change only colour of status bar content. Not even background of status bar. I want exactly same out put as I post picture in my question. First image in my question. – nilkash Apr 28 '14 at 13:27
0

This can be done simply . Please check out these StackOverflow links to see the best fit for you. My advice is to look more . The status bar is made by default as transparent in iOS 7 so we need to apply these procedures to make it look like it was before iOS 7.

Status bar and navigation bar issue in IOS7

How to set Status bar background color iOS 7

Community
  • 1
  • 1
IronManGill
  • 7,222
  • 2
  • 31
  • 52
  • Thank you for your quick response. Can You please check question once agin properly. I tried something which is working for If I have navigation bar in my view. But If I set navigation bar hidden it not not working properly. It still shows content of status bar in black colour. So I need solution for that. Other wise If I se t navigation bar then its working fine. Need Help. Thank you. – nilkash Apr 28 '14 at 10:06
0

You should use:

self.navigationController.navigationBar.hidden = YES;

instead of:

self.navigationController.navigationBarHidden = YES;

NavigationBar hidden behavior can be strange if UIViewController is child viewController of UINavigationController.

Bellow comments are research from @Tyson and @ing0 in this answer: For anyone using a UINavigationController:

The UINavigationController does not forward on preferredStatusBarStyle calls to its child view controllers. Instead it manages its own state - as it should, it is drawing at the top of the screen where the status bar lives and so should be responsible for it. Therefor implementing preferredStatusBarStyle in your VCs within a nav controller will do nothing - they will never be called.

The trick is what the UINavigationController uses to decide what to return for UIStatusBarStyleDefault or UIStatusBarStyleLightContent. It bases this on it's UINavigationBar.barStyle. The default (UIBarStyleDefault) results in the dark foreground UIStatusBarStyleDefault status bar. And UIBarStyleBlack will give a UIStatusBarStyleLightContent status bar.

TL;DR:

If you want UIStatusBarStyleLightContent on a UINavigationController use:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
Community
  • 1
  • 1
inix
  • 485
  • 1
  • 5
  • 12