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


当前回答

如果你有一个通过Interface Builder创建的嵌入式导航控制器,请确保在管理导航控制器的类中设置以下内容:

-(UIStatusBarStyle)preferredStatusBarStyle{ 
    return UIStatusBarStyleLightContent; 
} 

这应该就是你所需要的。

其他回答

在AppDelegate。M,添加以下内容。

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

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

} 

在Plist文件中,将“基于视图控制器的状态栏外观”设置为NO。

这适用于Golden Master iOS7和Xcode 5 GM种子和2013年9月18日发布的iOS7 SDK(至少导航控制器隐藏):

中的UIViewControllerBasedStatusBarAppearance设置为NO Info.plist。 在ViewDidLoad方法或任何地方,你想改变的地方 状态栏样式: [[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];
    }

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

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

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

在ios7上,如果你想使用UIViewControllerBasedStatusBarAppearance == YES,并且你的根视图控制器是UINavigationController,你应该这样做 子类化它并重载childViewControllerForStatusBarStyle,例如:

- (UIViewController*) childViewControllerForStatusBarStyle
{
    return self.viewControllers.lastObject;
}

在这之后,preferredStatusBarStyle将在被推送的视图控制器上被调用。