更改状态栏颜色Objective-C

问题描述:

在我的应用程序中,有一个黑暗模式,我想知道如何更改状态栏的颜色? 谢谢,更改状态栏颜色Objective-C

UIColor *color = [UIColor whiteColor]; 
self.navigationController.navigationBar.barTintColor = color; 

可以低于在AppDelegate.mdidFinishLaunchingWithOptions方法的代码行可能有助于:

[application setStatusBarHidden:NO]; 

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 

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

if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) { 

    statusBar.backgroundColor = [UIColor whiteColor];//set whatever color you like 
} 
+0

不这样做,这是一个黑客,可能让你的应用程序被拒绝使用私有的API就像一个魅力 – Dvole

+1

工作 –

夫特3溶液:
在需要非默认状态栏外观视图控制器,使用这个:

override var preferredStatusBarStyle: UIStatusBarStyle { 
    return .lightContent 
} 

一个简单而有效的方法是将属性添加到info.plist并将状态栏样式设置为UIStatusBarStyleLightContent

This works like a charm

我们应该做的是:

  • 首先打开info.plist文件的应用程序,然后添加属性UIViewControllerBasedStatusBarAppearance,并将其值设置为NO
  • 下一页头到您Appdelegate或任何类别文件并使用以下代码:

    UIApplication.sharedApplication.statusBarStyle = UIStatusBarStyleLightContent; 
    

    另一种编写代码的方法是:

    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];