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

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

查看更多
还给你的自由
3楼-- · 2018-12-31 02:39

Alternatively, you can opt out of the view-controller based status bar appearance:

  1. Set View controller-based status bar appearance to NO in your Info.plist.
  2. Call [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

Note: This method has been deprecated in iOS9. Use preferredStatusBarStyle on the UIViewController instead. (see Apple Developer Library)

查看更多
长期被迫恋爱
4楼-- · 2018-12-31 02:40

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's Info.plist file and give it the value YES.

I'd definitely recommend having a look through the document, which, again, you can access with your Apple developer ID.

查看更多
旧人旧事旧时光
5楼-- · 2018-12-31 02:41

If you still want to use View controller-based status bar appearance in info.plist set to YES, meaning that you can change the statusbar for each view-controller, use the following for white text in the status-bar in ViewDidLoad:

[[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlackTranslucent];
查看更多
时光乱了年华
6楼-- · 2018-12-31 02:42

Let me give you a complete answer to your question. Changing the status bar text color is very easy but its a little confusing in iOS 7 specially for newbies.

If you are trying to change the color from black to white in Storyboard by selecting the view controller and going to Simulated Metrics on the right side, it won't work and i don't know why. It should work by changing like this but any how.

Secondly, 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.

ios 7 status bar text color

Lastly, you have to go to your AppDelegate.m file and add the following in didFinishLaunchingWithOptions method, add the following line:

     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

This will change the color to white for all your view controllers. Hope this helps!

查看更多
高级女魔头
7楼-- · 2018-12-31 02:42

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

  1. Set the UIViewControllerBasedStatusBarAppearance to NO in the Info.plist.

  2. In ViewDidLoad method or anywhere, where do you want to change status bar style: [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

查看更多
登录 后发表回答