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

Well, this is really working like a piece of cake for me.

Go to your app's info.plist.

  1. Set View controller-based status bar appearance to NO
  2. Set Status bar style to UIStatusBarStyleLightContent

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.

查看更多
路过你的时光
3楼-- · 2018-12-31 02:52

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 call setNeedsStatusBarAppearanceUpdate.

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/

查看更多
泪湿衣
4楼-- · 2018-12-31 02:56

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
查看更多
不再属于我。
5楼-- · 2018-12-31 02:58

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"

查看更多
素衣白纱
6楼-- · 2018-12-31 03:00
  1. Go to Project -> Target,

  2. Then set Status Bar Style to Light. It makes status-bar white from the launch screen. Project Setting

  3. Then set View controller-based status bar appearance equal to NO in Info.plist.

查看更多
春风洒进眼中
7楼-- · 2018-12-31 03:00

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.

查看更多
登录 后发表回答