155

In iOS 9, how do I change the color of the status bar text to white?

Cœur
  • 37,241
  • 25
  • 195
  • 267
reza_khalafi
  • 6,230
  • 7
  • 56
  • 82
  • you shouldnt customise the status bar. Choose one of the status bar style available. The text color should be white, when the statusbar is on dark background. – Teja Nandamuri Oct 13 '15 at 13:29
  • please check my answer and tell me review @reza_darkman797 – Jay Bhalani Oct 13 '15 at 13:56
  • 2
    On iOS9 just this in the AppDelegate works... ```[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];``` – Dimitris Apr 28 '16 at 17:01
  • Heads up - `setStatusBarStyle` is deprecated on iOS 9... use `preferredStatusBarStyle` instead. – siege_Perilous Jun 02 '16 at 23:56
  • THE STATUS BAR CONTENT IS BASED ON NAVIGATION CONTROLLER BAR STYLE. SO ALL YOU NEED TO DO IS JUST ADD THE LINE IN YOUR ViewDidLoad(): [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack]; Default is Black. ie, [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault]; – Ram Madhavan Sep 07 '17 at 06:00

6 Answers6

420

If you want to change Status Bar Style from the launch screen, You should take this way.

  1. Go to Project -> Target,

  2. Set Status Bar Style to Light Project Setting

  3. Set View controller-based status bar appearance to NO in Info.plist.

Wanbok Choi
  • 5,432
  • 1
  • 21
  • 26
115

Using a UINavigationController and setting its navigation bar's barStyle to .Black. past this line in your AppDelegate.m file.

navigationController.navigationBar.barStyle = UIBarStyleBlack;

If you are not using UINavigationController then add following code in your ViewController.m file.

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

And call the method to this line :

[self setNeedsStatusBarAppearanceUpdate];
Jay Bhalani
  • 4,142
  • 8
  • 37
  • 50
42

First set

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

Go to your AppDelegate, find itsdidFinishLaunchingWithOptions method and do:

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

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

}

and then set View controller-based status bar appearance equal to NO in plist.

mfaani
  • 33,269
  • 19
  • 164
  • 293
reza_khalafi
  • 6,230
  • 7
  • 56
  • 82
  • 6
    Adding the entry to the plist is the most important part of this answer, without this then you won't be able to set the style on individual views – sam_smith Dec 21 '15 at 00:26
  • 23
    setStatusBarStyle is deprecated in iOS 9... – CodeSmith Jan 05 '16 at 02:20
  • 4
    Since iOS 9, this method is deprecated. Use the ViewController method instead : - (UIStatusBarStyle)preferredStatusBarStyle {return UIStatusBarStyleLightContent;}` You will also need to add this key in your Info.plist : "UIViewControllerBasedStatusBarAppearance" – Hugo Jan 06 '16 at 18:53
  • Got it Working in Xcode 8 -iOS10 (through the project properties Statusbar: Light and in the plist ViewController-based status bar appearance: NO.Perfect Thanks – Remco Nov 21 '16 at 20:44
37
  1. Add a key in your info.plist file UIViewControllerBasedStatusBarAppearance and set it to YES.

  2. In viewDidLoad method of your ViewController add a method call:

    [self setNeedsStatusBarAppearanceUpdate];
    
  3. Then paste the following method in viewController file:

    - (UIStatusBarStyle)preferredStatusBarStyle
    { 
        return UIStatusBarStyleLightContent; 
    }
    
Mr Rogers
  • 6,091
  • 2
  • 32
  • 34
Vijay Yadav
  • 511
  • 5
  • 14
  • 1
    This is what I wanted because I only want to change the style for that one view controller. – Mr Rogers Feb 19 '16 at 02:18
  • 1
    you can also just set the status bar style in the ViewController's .xib (i.e. instead of adding the prefferedStatusBarStyle method) – Chris Allinson Nov 17 '16 at 17:34
  • for UIStatusBarStyleLightContent, you can also select Light in the General Tab after you select your project. No code required. – coolcool1994 Feb 16 '18 at 05:48
12

Add the key View controller-based status bar appearance to Info.plist file and make it boolean type set to NO.

Insert one line code in viewDidLoad (this works on specific class where it is mentioned)

 [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
squarefrog
  • 4,750
  • 4
  • 35
  • 64
Maninderjit Singh
  • 1,419
  • 1
  • 13
  • 23
  • 1
    `statusBarStyle` is readonly: `@property(readonly, nonatomic) UIStatusBarStyle statusBarStyle` in iOS9. And `setStatusBarStyle` is deprecated – zxcat Feb 25 '16 at 13:48
1

iOS Status bar has only 2 options (black and white). You can try this in AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
}
budiDino
  • 13,044
  • 8
  • 95
  • 91
asim.temur
  • 61
  • 6
  • 1
    'setStatusBarStyle:' is deprecated: first deprecated in iOS 9.0 - Use -[UIViewController preferredStatusBarStyle] – omega1 Feb 14 '18 at 09:53