我的应用程序背景是黑色的,但在iOS 7中,状态栏变成了透明的。所以我什么也看不见,只有角落里的绿色电池指示灯。如何将状态栏文本颜色改为白色,就像在主屏幕上一样?


当前回答

只需改变1)信息。plist基于控制器的状态栏外观->否 和写 2)

  [[UIApplication
 sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent]; 

in

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

其他回答

如果你想将它设置为任何颜色,请使用下面的代码。

id statusBarWindow = [[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
id statusBar = [statusBarWindow valueForKey:@"statusBar"];

SEL setForegroundColor_sel = NSSelectorFromString(@"setForegroundColor:");
if([statusBar respondsToSelector:setForegroundColor_sel]) {
    // iOS 7+
    [statusBar performSelector:setForegroundColor_sel withObject:YourColorHere];
                                                                 ^^^^^^^^^^^^^
}

我知道我正在访问私有API,但我已经在许多项目中使用了这个,苹果已经批准了它。

在提交应用程序时,将此代码发送到Apple的评论部分,并告知您正在使用此代码更改状态栏的颜色。

是的,不要忘记下面的内容。

在信息。plist设置“视图基于控制器的状态栏外观”为NO

在AppDelegate中添加

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

请试试这个

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [application setStatusBarHidden:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = [UIColor blackColor];
    }

这在iOS 7 UI过渡指南中有记录,你需要一个苹果开发者ID才能直接访问。相关节选:

因为状态栏是透明的,所以它后面的视图是透视的。[…使用UIStatusBarStyle常量来指定状态栏内容应该是暗的还是亮的: UIStatusBarStyleDefault显示黑色内容。[…] UIStatusBarStyleLightContent显示轻内容。当状态栏后面是黑色内容时使用。

也可能令人感兴趣:

在iOS 7中,你可以通过单个的vew控制器控制状态栏的样式,并在应用程序运行时更改它。要选择这种行为,添加UIViewControllerBasedStatusBarAppearance键到应用程序的信息。plist文件并赋值YES。

我强烈建议你浏览一下这个文档,同样,你可以用你的苹果开发者ID访问这个文档。

在Plist中添加以下内容:

状态栏样式:UIStatusBarStyleLightContent 基于视图控制器的状态栏外观:NO