How to change Status Bar text color in iOS

2018-12-31 02:32发布

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?

30条回答
萌妹纸的霸气范
2楼-- · 2018-12-31 02:48

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: enter image description here

& 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:

enter image description here

Thats it.

查看更多
余生请多指教
3楼-- · 2018-12-31 02:48

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 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 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

enter image description here

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:

Setting the status bar style in code

查看更多
听够珍惜
4楼-- · 2018-12-31 02:49

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];
    …
}
查看更多
何处买醉
5楼-- · 2018-12-31 02:49

In case your UIViewController is inside a UINavigationController you will have to set the BarStyle:

-[UINavigationBar setBarStyle:UIBarStyleBlack]

Original Answer is here

https://devforums.apple.com/message/844264#844264

查看更多
千与千寻千般痛.
6楼-- · 2018-12-31 02:49

No need do some extra , just write this code in your viewController and get status bar color white

- (UIStatusBarStyle)preferredStatusBarStyle{return UIStatusBarStyleLightContent;}
查看更多
怪性笑人.
7楼-- · 2018-12-31 02:50

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.

查看更多
登录 后发表回答