iOS 修改状态栏字体颜色(亲测,好用)

1.首先是设置info.plist 文件:

将View controller-based status bar appearance 的值设置为NO。

2.在AppDelegate.m 的方法中如下设置,默认会显示黑色等于为你的app状态栏设置一个主颜色

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

    //设置全局状态栏字体颜色为黑色   

     [UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleDefault;

    //设置全局状态栏字体颜色为白色

    // [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    returnYES;

}

3.在需要设置为白色的地方添加如下代码:

[UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleLightContent;

4.在需要变回黑色的地方添加如下代码:

[UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleDefault;

例如你想将一个控制器的状态栏的字体颜色设为白色代码如下:

#pragma mark - 设置状态栏颜色

-(void)viewWillAppear:(BOOL)animated{   

     [superviewWillAppear:animated];   

     [UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleLightContent;   

 }

-(void)viewWillDisappear:(BOOL)animated{      

      [superviewWillDisappear:animated];       

     [UIApplicationsharedApplication].statusBarStyle =UIStatusBarStyleDefault; 

 }

推荐阅读更多精彩内容