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


当前回答

在Xcode中最简单的方法(不需要任何编码)是:

添加基于视图控制器的状态栏外观到您的信息。plist,设置为NO。 现在,转到项目目标,在部署信息中,你会发现一个状态栏样式的选项。将此选项的值设置为Light。

你会看到白色状态栏。

其他回答

请试试这个

[[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 6和7中使用这个:

#ifdef __IPHONE_7_0
# define STATUS_STYLE UIStatusBarStyleLightContent
#else
# define STATUS_STYLE UIStatusBarStyleBlackTranslucent
#endif

[[UIApplication sharedApplication] setStatusBarStyle:STATUS_STYLE animated:YES];

不需要做一些额外的,只是写这段代码在你的viewController和获得状态栏颜色白色

- (UIStatusBarStyle)preferredStatusBarStyle{return UIStatusBarStyleLightContent;}

简单地在应用程序委托:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

在Swift 5中,遵循以下步骤:

在Info.plist中添加key UIViewControllerBasedStatusBarAppearance并将value设置为false 添加键UIStatusBarStyle和设置值UIStatusBarStyleLightContent

这些对我来说都没用,所以这里有一个有效的解决方案……

在信息。Plist,添加一行:

UIViewControllerBasedStatusBarAppearance,并设置值为NO。

然后在AppDelegate的didFinishLaunchingWithOptions中添加这些行:

[application setStatusBarHidden:NO];
[application setStatusBarStyle:UIStatusBarStyleLightContent];