My application has a dark background, but in iOS 7 the status bar became transparent. So I can't see anything there, only the green battery indicator in the corner. How can I change the status bar text color to white like it is on the home screen?
-
Look my naswer for better solution stackoverflow.com/questions/17678881/…– UcdemirDec 19, 2020 at 7:00
-
Xcode seems to be constantly changing this, so I recommend scrolling down to find the more recent solutions (e.g., Super simple answer as of 2021).– Eric33187Apr 2, 2021 at 18:45
61 Answers
Set the
UIViewControllerBasedStatusBarAppearance
toYES
in the .plist file.In the
viewDidLoad
do a[self setNeedsStatusBarAppearanceUpdate];
Add the following method:
- (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; }
Note: This does not work for controllers inside UINavigationController
, please see Tyson's comment below :)
Swift 3 - This will work controllers inside UINavigationController
. Add this code inside your controller.
// Preferred status bar style lightContent to use on dark background.
// Swift 3
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Swift 5 and SwiftUI
For SwiftUI create a new swift file called HostingController.swift
import Foundation
import UIKit
import SwiftUI
class HostingController: UIHostingController<ContentView> {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
Then change the following lines of code in the SceneDelegate.swift
window.rootViewController = UIHostingController(rootView: ContentView())
to
window.rootViewController = HostingController(rootView: ContentView())
-
83
-
42Doesn't seem to be working on iOS 7 Beta 5 with Xcode5-DP5. preferredStatusBarStyle doesn't seem to get called. Aug 12, 2013 at 10:28
-
20UIViewControllerBasedStatusBarAppearance is changed to View controller-based status bar appearance in Xcode 5 GM seed Sep 11, 2013 at 13:28
-
44Got the answer for Xcode GM Seed : 1. In Info.plist put View controller-based status bar appearance as NO 2. In appDelegate, inside appDidFinishLaunching method, put [[UIView appearance] setTintColor:[UIColor whiteColor]]; Sep 13, 2013 at 13:47
-
111UINavigationController is a special case, the above will not work. Just spent hours scratching my head over this. See here for solution: stackoverflow.com/a/19513714/505457– TysonOct 22, 2013 at 9:27
Alternatively, you can opt out of the view-controller based status bar appearance:
- Set
View controller-based status bar appearance
toNO
in yourInfo.plist
. - Call
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Note: This method has been deprecated in iOS9. Use preferredStatusBarStyle
on the UIViewController instead. (see Apple Developer Library)
-
18
-
235No need to code. It can all be done from the plist: (1) set "View controller-based status bar appearance" to NO and (2) set "Status bar style" to "Opaque black style". (Raw values are UIViewControllerBasedStatusBarAppearance -> NO and UIStatusBarStyle -> UIStatusBarStyleBlackOpaque) Sep 20, 2013 at 5:15
-
4Note that you must set the relevant info.plist value to NO for this to work. Sep 29, 2013 at 23:34
-
10@gothicdev: nice catch. Would accept your answer as it is the cleanest. Light option for Bar Style could be: UIStatusBarStyleLightContent– benkaOct 30, 2013 at 14:05
-
11
You can do this without writing any line of code!
Do the following to make the status bar text color white through the whole app
On you project plist file:
- Status bar style:
Transparent black style (alpha of 0.5)
- View controller-based status bar appearance:
NO
- Status bar is initially hidden:
NO
-
13I don't know if things changed, but the UIStatusBarStyleLightContent value is not recognized by XCode, and not found in any documentation... Although it seems to work.– Nathan HSep 11, 2013 at 12:29
-
6This one also changed it on the splash screen, whereas just setting it on the navigator wouldn't... Kudos! Oct 30, 2013 at 14:11
-
4Definitely the easiest way to get this done and as mentioned also works on splash screen.– 7wondersNov 5, 2013 at 18:18
-
5There isn't anything called
UIStatusBarStyleLightContent
in theplist info
HOWEVER there isTransparent Black
which will do the same trick :) plus, you need to addView controller-based status bar appearance
as it's not there originally and it's all what you need to get it to work :) Feb 3, 2014 at 18:01 -
49For lazy people like me, copy and past away:
<key>UIStatusBarStyle</key> <string>UIStatusBarStyleLightContent</string> <key>UIViewControllerBasedStatusBarAppearance</key> <false/>
Jun 28, 2014 at 23:23
Note: The most upvoted answer does not work for iOS 7 / 8
In Info.plist set 'View controller-based status bar appearance' as NO
In AppDelegate add
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
to
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
...
}
This solution works for iOS 7 / 8.
-
12
For me, nothing happened with using all the things in the other answers (and from other sources/documentation). What did help was to set the Navigation Bar Style to "Black" in the XIB. This changed the text to white without any code at all.
-
3In the device none of the answers above worked for me but this one. I think it tells everything about the new system that you have to set the navigation_bar to BLACK to have the status_bar text WHITE.– MrTJSep 19, 2013 at 15:48
-
2After struggling through lots of things, this is what ended up working. The Style was set to default. Changed this and stripped out all the other status bar hacks and it works.– KuditNov 17, 2013 at 20:01
-
1If you don't want to set all your nav bars in IB you can also set its appearance proxy. [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack]; Mar 7, 2014 at 15:06
-
3Doesn't work for me in iOS7 Storyboard. Looks like this might be a side-effect os something else?– ChrisMar 12, 2014 at 12:33
-
I would like to confirm that, all of the above answers not have worked for me neither. Following the image, the status bar text looks white. But I repeat again, the above ANSWERS with Xcode 6.2 and iOS 8.2 do not work.– MarkusMar 23, 2015 at 11:27
None of that worked for me, so here is a working solution...
In Info.plist
, add a row:
UIViewControllerBasedStatusBarAppearance
, and set the value NO
.
Then in AppDelegate in didFinishLaunchingWithOptions
, add these rows:
[application setStatusBarHidden:NO];
[application setStatusBarStyle:UIStatusBarStyleLightContent];
-
-
Awesome but this UIViewControllerBasedStatusBarAppearance converts to same : View controller-based status bar appearance Automatically :) Jun 17, 2016 at 12:47
You dont need to do any code for this
You need to add "View controller-based status bar appearance" key in info.plist as follows:
& set its value type to Boolean & value to NO. Then click on project settings,then click on General Tab & under Deployment Info set the preferred status bar style to .Light as follows:
Thats it.
-
1I liked your approach! In my case, I was trying to figure out how to make the status bar style to be light only when it is fullscreen (w/o navigation bar). Then, I realized that all other screens should fit the same light style. So a good solution is to set for whole thing. Thanks! (: Feb 13, 2016 at 3:51
-
If you don't need to change this ever while your app is running. This is the best approach.– MichaelMay 25, 2016 at 1:18
-
This approach definitely works but it introduces a strange issue on iPad. In case your application supports deeplinks, and when you launch application through deeplink the backlink appearing on status bar disappears. Dec 2, 2016 at 10:30
-
-
Just two steps as following:
Step 1:
Under the Info tab of the project target
, Add Row:
UIViewControllerBasedStatusBarAppearance
, set value NO
.
Step 2:
In the project AppDelegate.m
:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
…
[application setStatusBarStyle:UIStatusBarStyleLightContent];
…
}
-
4I love this answer for it's the first time I'm using the "application" param )) Feb 13, 2014 at 14:53
-
This works in Golden Master iOS 7 and Xcode 5 GM seed and iOS7 SDK released on September 18th, 2013 (at least with navigation controller hidden):
Set
the UIViewControllerBasedStatusBarAppearance
toNO
in theInfo.plist
.In
ViewDidLoad
method or anywhere, where do you want to change status bar style:[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
-
1UIViewControllerBasedStatusBarAppearance default values seems to be YES. "Apps default to using the new view controller-based status bar management system. To opt out of this, add a value of NO for the UIViewControllerBasedStatusBarAppearance key to your Info.plist." [bgr.com/2013/09/10/ios-7-gm-change-log-release-notes/]– ZsoltSep 14, 2013 at 10:20
-
1Ya!!After setting the UIViewControllerBasedStatusBarAppearance to NO,status bar hides in the views. Sep 22, 2013 at 16:10
-
-
You can add it just in appDelegates didFinishLoading method. Or in first views viewDidLoad method if you don't want it to change. Sep 23, 2013 at 14:58
-
1
If you have an embedded navigation controller created via Interface Builder, be sure to set the following in a class that manages your navigation controller:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
That should be all you need.
-
This was the only solution that worked for me in a storyboard-less and xib-less app. Should be helpful for non-IB users too. Sep 26, 2013 at 17:28
-
2This was perfect for me when I needed to set the style differently in each view controller– BenOct 3, 2013 at 2:15
-
If you want to retain "View controller-based status bar appearance" set to yes, this is the way to go. Thanks! Mar 25, 2014 at 0:44
In case your UIViewController is inside a UINavigationController you will have to set the BarStyle:
-[UINavigationBar setBarStyle:UIBarStyleBlack]
Original Answer is here
-
No, this simply makes the navigation bar colour the same as the status bar text colour. This hides the problem, not fixes it!– wpearseDec 1, 2013 at 20:10
-
2In iOS7 the status bar will mimic the UINavigationBar if the view contains a UINavigationController, so in many cases, this is the correct answer.– jonstaffJan 22, 2014 at 3:44
I'm using Xcode 6 beta 5 on a Swift project, for an iOS 7 app.
Here is what I did, and it works:
info.plist:
-
2Thanks it's look like only your solution working with latest ver of IOS7 Sep 7, 2014 at 23:33
-
This solution shows status bar while loading the app, in the launch screen. Nov 19, 2015 at 19:27
-
Solved my issues in xCode 7.1. Latest Version. Apple forgot a couple crucial pieces to make something work. Again.– MichaelNov 28, 2015 at 19:37
-
2The second part where you set the actual
View controller-based status bar appearance equal
toNO
was the piece I was missing. Thanks– WillJun 3, 2016 at 22:05 -
In Swift 3 is very easy just with 2 steps.
Go to your info.plist and change the key View controller-based status bar appearance
to "NO".
Then in the Appdelegate just add this line in didfinishlaunchingwithoptions method
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UIApplication.shared.statusBarStyle = .lightContent
return true
}
this has been deprecated in iOS9 now you should do override this property in the rootviewcontroller
doing this has been deprecated in iOS 9 should do this on the rootviewcontroller
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
-
1
-
doing this has been deprecated in iOS 9 should do this on the rootviewcontroller override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } Jan 5, 2019 at 2:36
In AppDelegate.m, add the following.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
And in the Plist file, set 'View controller-based status bar appearance' to NO.
Simply In App Delegate:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
In Swift 5, Follow the below steps:
- Add key
UIViewControllerBasedStatusBarAppearance
and set value tofalse
in Info.plist - Add key
UIStatusBarStyle
and set value toUIStatusBarStyleLightContent
-
5
-
6But for this we need to opt out View controller-based status bar appearance . Feb 12, 2014 at 11:21
-
Xcode constantly seems to change this, so this is the latest.
As of 2021 - Swift 5, Xcode 12
To change the status bar to white:
- Open your Info.plist.
- Add key
UIViewControllerBasedStatusBarAppearance
and set value toNo
(false). The human readable version of this is"View controller-based status bar appearance"
. - Add key
UIStatusBarStyle
and set value toUIStatusBarStyleLightContent
(i.e.,"Light Content"
).
-
1
Well, this is really working like a piece of cake for me.
Go to your app's info.plist
.
- Set
View controller-based status bar appearance
toNO
- Set
Status bar style
toUIStatusBarStyleLightContent
Then go to your app's delegate and paste in the following code where you set your windows's RootViewController.
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
view.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
[self.window.rootViewController.view addSubview:view];
}
Bingo. It's working for me.
-
1i think this is the correct answer (the part of the plist)... why would I add static code on didfinishlaunchingwithoptions... If you need same color for the whole app this is the right way Jun 18, 2014 at 21:21
iOS 7 allows individual view controllers to determine the appearance of the status bar, as described by the Apple developer documentation:
iOS 7 gives view controllers the ability to adjust the style of the status bar while the app is running. A good way to change the status bar style dynamically is to implement
preferredStatusBarStyle
and—within an animation block—update the status bar appearance and callsetNeedsStatusBarAppearanceUpdate
.
Setting the status bar appearance globally is a two-step process.
First, you need to tell iOS that you don't want to set the status bar appearance on a view-by-view basis.
Then you need to take charge and actually set the new global status bar style.
To disable view-by-view status bar control, you'll need to set the View controller-based status bar appearance
property in Info.plist
.
Open the Project Navigator and select the project for your iOS app, then select the Info tab.
Hover over a row, then click the plus sign that appears to add a new property to your .plist
.
Enter View controller-based status bar appearance
in the Key field, then make sure the Type field is set to Boolean
. Finally, enter NO
in the Value field.
To set a global style for the status bar, add another property under the Info tab with a key of Status bar style
, a Type of String
and a Value of Opaque black style
.
Here's a blog post with a little more detail and some sample code:
http://codebleep.com/setting-the-status-bar-text-color-in-ios-7/
-
Thanks. My issue was that I didn't see that the type of "View controller-based status bar appearance" was set to String. Editing the .plist file "by hand" and putting in the boolean value cleared things up. Jun 23, 2014 at 1:48
Answer updated for for Xcode GM Seed:
In
Info.plist
putView controller-based status bar appearance
asNO
In the project, set:
In ViewDidLoad:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
No need do some extra , just write this code in your viewController and get status bar color white
- (UIStatusBarStyle)preferredStatusBarStyle{return UIStatusBarStyleLightContent;}
-
Put this under ViewController.m after implementation. Its the easiest and works great! Thank you Mohit! Oct 7, 2014 at 2:37
This is documented in the iOS 7 UI Transition Guide, which you need an Apple developer ID to access directly. The relevant excerpt:
Because the status bar is transparent, the view behind it shows through. [...] Use a
UIStatusBarStyle
constant to specify whether the statusbar content should be dark or light:
UIStatusBarStyleDefault
displays dark content. [...]
UIStatusBarStyleLightContent
displays light content. Use when dark content is behind the status bar.
Also possibly of interest:
In iOS 7, you can control the style of the status bar from an individual vew controller and change it while the app runs. To opt in to this behavior, add the
UIViewControllerBasedStatusBarAppearance
key to an app'sInfo.plist
file and give it the valueYES
.
I'd definitely recommend having a look through the document, which, again, you can access with your Apple developer ID.
-
3I have already tried [application setStatusBarStyle:UIStatusBarStyleLightContent]; but actually nothing changes, text color is still black Jul 16, 2013 at 14:31
-
I'd love to be of more help, but like I say, I'm not familiar enough with the iOS development process to know what to suggest. Sorry! Jul 16, 2013 at 15:57
-
11) set the UIViewControllerBasedStatusBarAppearance to YES in the plist 2) in viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate]; 3) add the following method:-(UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent; } Jul 21, 2013 at 3:32
I think all the answers do not really point the problem because all of them work in specific scenarios. But if you need to cover all the cases follow the points bellow:
Depending on where you need the status bar light style you should always have in mind these 3 points:
1)If you need the status bar at the launch screen or in other places, where you can't control it (not in view controllers, but rather some system controlled elements/moments like Launch Screen) You go to your project settings
2) if you have a controller inside a navigation controller You can change it in the interface builder as follows:
a) Select the navigation bar of your navigation controller
b) Then set the style of the navigation bar to "Black", because this means you'll have a "black" -> dark background under your status bar, so it will set the status bar to white
Or do it in code as follows
navigationController?.navigationBar.barStyle = UIBarStyle.Black
3) If you have the controller alone that needs to have it's own status bar style and it's not embedded in some container structure as a UINavigationController
Set the status bar style in code for the controller:
-
-
1I had to add StatusBarIsIntiallyHidden = NO to the plist as well as ViewControllerBasedApplicationStatusBarAppearnce = NO to the plist. Then this works using part one– MichaelNov 29, 2015 at 21:23
-
Did you have a splashscreen which has the same "image" as the first loading view controller? And also, in the "Info" section of your target you can try setting the "Hide status bar" to false and avoid dealing with your .plist. "StatusBarIsIntiallyHidden" flag– FawkesNov 29, 2015 at 21:28
-
-
I actually found this issue when creating a fresh project in xCode 7.1 which is why I thought it was so strange– MichaelNov 29, 2015 at 21:29
Here is Apple Guidelines/Instruction about status bar change. Only Dark & light (while & black) are allowed in status bar.
Here is - How to change status bar style:
If you want to set status bar style, application level then set UIViewControllerBasedStatusBarAppearance
to NO
in your `.plist' file.
if you wan to set status bar style, at view controller level then follow these steps:
- Set the
UIViewControllerBasedStatusBarAppearance
toYES
in the.plist
file, if you need to set status bar style at UIViewController level only. In the viewDidLoad add function -
setNeedsStatusBarAppearanceUpdate
override preferredStatusBarStyle in your view controller.
-
override func viewDidLoad() {
super.viewDidLoad()
self.setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Set value of .plist according to status bar style setup level.
Here is some hacky trick to change/set background color for status bar during application launch or during viewDidLoad of your view controller.
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
// Set upon application launch, if you've application based status bar
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
return true
}
}
or
// Set it from your view controller if you've view controller based statusbar
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
}
}
Here is result:
Simply calling
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
in the
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
}
method of my AppDelegate
works great for me in iOS7.
-
Wow, lotsa crap here but this answer worked for me. I'm using Xcode 6 and iOS 8 SDK Jan 28, 2015 at 23:35
-
1Excellent, works for me in iOS 9 with
View controller-based status bar appearance = NO
– dstudebaOct 19, 2015 at 2:58
In my case for Swift 5, I added these lines:
override func viewDidAppear(_ animated: Bool) {
navigationController?.navigationBar.barStyle = .black
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
-
preferredStatusBarStyle didn't do anything though. .black can go in viewDidLoad just fine. Nov 3, 2020 at 19:04
I did some things different and it works for me.
With no changes in code, I did config my .plist file like this:
- View controller-based status bar appearance > NO
- Status bar style > UIStatusBarStyleLightContent (simple string)
I hope it helps.
edit
For each view controller I change the "status bar"'s Simulated Metrics property, in storyboard, from "inferred" to "Light Content"
in info.plist set the field value NO View controller-based status bar appearance and set statusbar style light in target > general setting.
-
2
Just to summarize, edit your project Info.plist
and add:
View controller-based status bar appearance
: NO
Status bar style
: Opaque black style
or if you have raw key/value plist
UIViewControllerBasedStatusBarAppearance
: NO
UIStatusBarStyle
: Opaque black style
-
this worked for me and its less of a hassle than using
preferredStatusBarStyle
since you can configure it globally (of course that's only useful it appropriate to your case)– nburkNov 30, 2014 at 11:48
If you want the same result with Swift, you can use this code in your AppDelegate.swift file :
UINavigationBar.appearance().barStyle = .BlackTranslucent
And the text of your status bar will be white :-) !