使用 Objective-C 在 iOS 9 中将状态栏文本颜色更改为浅色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33103831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:36:30  来源:igfitidea点击:

Change status bar text color to light in iOS 9 with Objective-C

objective-cios9xcode7statusbar

提问by reza_khalafi

In iOS 9, how do I change the color of the status bar text to white?

在 iOS 9 中,如何将状态栏文本的颜色更改为白色?

回答by Wanbok Choi

If you want to change Status Bar Style from the launch screen, You should take this way.

如果您想从启动屏幕更改状态栏样式,您应该采用这种方式。

  1. Go to Project-> Target,

  2. Set Status Bar Styleto LightProject Setting

  3. Set View controller-based status bar appearanceto NOin Info.plist.

  1. Project-> Target,

  2. 设置Status Bar StyleLight项目设置

  3. 设置View controller-based status bar appearanceNOInfo.plist

回答by Jay Bhalani

Using a UINavigationControllerand setting its navigation bar's barStyleto .Black. past this line in your AppDelegate.mfile.

使用 aUINavigationController并将其导航栏设置barStyle.Black。在您的AppDelegate.m文件中超过这一行。

navigationController.navigationBar.barStyle = UIBarStyleBlack;

If you are not using UINavigationControllerthen add following code in your ViewController.mfile.

如果您不使用,UINavigationController则在您的ViewController.m文件中添加以下代码。

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

And call the method to this line :

并将方法调用到这一行:

[self setNeedsStatusBarAppearanceUpdate];

回答by reza_khalafi

First set

第一套

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

Go to your AppDelegate, find itsdidFinishLaunchingWithOptionsmethod and do:

转到您的 AppDelegate,找到它的didFinishLaunchingWithOptions方法并执行以下操作:

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

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

}

and then set View controller-based status bar appearanceequal to NO in plist.

然后View controller-based status bar appearance在 plist 中设置为等于 NO。

回答by Vijay Yadav

  1. Add a key in your info.plistfile UIViewControllerBasedStatusBarAppearanceand set it to YES.

  2. In viewDidLoad method of your ViewController add a method call:

    [self setNeedsStatusBarAppearanceUpdate];
    
  3. Then paste the following method in viewControllerfile:

    - (UIStatusBarStyle)preferredStatusBarStyle
    { 
        return UIStatusBarStyleLightContent; 
    }
    
  1. 在您的info.plist文件中添加一个密钥UIViewControllerBasedStatusBarAppearance并将其设置为YES.

  2. 在 ViewController 的 viewDidLoad 方法中添加一个方法调用:

    [self setNeedsStatusBarAppearanceUpdate];
    
  3. 然后将以下方法粘贴到viewController文件中:

    - (UIStatusBarStyle)preferredStatusBarStyle
    { 
        return UIStatusBarStyleLightContent; 
    }
    

回答by Maninderjit Singh

Add the key View controller-based status bar appearanceto Info.plistfile and make it boolean type set to NO.

将密钥添加View controller-based status bar appearanceInfo.plist文件并将其布尔类型设置为NO.

Insert one line code in viewDidLoad(this works on specific class where it is mentioned)

插入一行代码viewDidLoad(这适用于提到它的特定类)

 [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

回答by asim.temur

iOS Status bar has only 2 options (black and white). You can try this in AppDelegate:

iOS 状态栏只有 2 个选项(黑色和白色)。你可以在 AppDelegate 中试试这个:

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