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


当前回答

在iOS 8中: add NavigationController.NavigationBar.BarStyle = UIBarStyle.Black;对viewDidLoad

其他回答

如果你的UIViewController在UINavigationController中,你必须设置BarStyle:

-[UINavigationBar setBarStyle:UIBarStyleBlack]

原始答案在这里

https://devforums.apple.com/message/844264#844264

这招对我很管用:

在plist中设置UIViewControllerBasedStatusBarAppearance为YES rootViewController需要方法实现 ——(UIStatusBarStyle) preferredStatusBarStyle

因为我的rootViewController是由Cocoapods (JASidePanelController)管理的,我通过一个类别添加了这个方法:

#import "JASidePanelController+StatusBarStyle.h"

@implementation JASidePanelController (StatusBarStyle)

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

@end

我必须为swift和导航控制器做些什么

extension UINavigationController {
    override open var preferredStatusBarStyle: UIStatusBarStyle {
       return .lightContent
    }   
}

请试试这个

[[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];
    }

如果我使用UINavigationController,我在iOS 9和Swift 2.0中做这个

self.navigationController?.navigationBar.barStyle = UIBarStyle.Black

如果我使用模态segue

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
}