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


当前回答

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

在信息。Plist,添加一行:

UIViewControllerBasedStatusBarAppearance,并设置值为NO。

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

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

其他回答

只需以下两步:

步骤1:

在项目目标的Info选项卡下,添加行:

UIViewControllerBasedStatusBarAppearance,设置值NO。

步骤2:

在项目AppDelegate.m中:

- (BOOL)application:(UIApplication *)application 
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    …
    [application setStatusBarStyle:UIStatusBarStyleLightContent];
    …
}

简单地在应用程序委托:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

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

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

我在一个Swift项目中使用Xcode 6 beta 5,用于iOS 7应用程序。

以下是我所做的,而且很有效:

info.plist:

你可以在iOS 6和7中使用这个:

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

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

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

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的评论部分,并告知您正在使用此代码更改状态栏的颜色。

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