简体   繁体   English

状态栏显示黑色文本,仅在iPhone 6 iOS 8模拟器上显示

[英]Status Bar showing black text, only on iPhone 6 iOS 8 simulator

I'm trying to convert my iOS 7 app to iOS 8 in Xcode 6 GM, and when i run it on the iPhone 5s or lower simulators with iOS 8 everything is fine, but on the iPhone 6 and 6 Plus simulators, the Status Bar has black text instead of white like it is everywhere anytime else. 我正在尝试将我的iOS 7应用程序转换为Xcode 6 GM中的iOS 8,当我在iOS 5或更低版本的iOS 8上运行它时,一切都很好,但在iPhone 6和6 Plus模拟器上,状态栏有黑色文字而不是白色,就像它随处可见。 I've set the Info.plist UIStatusBarStyle to "Transparent Black Style (alpha of 0.5)" thru Xcode, and that seems to have the desired effect everywhere else. 我通过Xcode将Info.plist UIStatusBarStyle设置为“透明黑色样式(alpha of 0.5)”,这似乎在其他地方都有所需的效果。 Any ideas what is going on? 有什么想法发生了什么?

(I haven't touched any of the storyboards yet, could it be anything with that? I was hoping I could put that off for a while:) (我还没有触及任何故事板,它可能是什么东西吗?我希望我能把它关掉一段时间:)

So here is how I fixed it 所以这就是我修复它的方法

In PLIST View Controller Based Status Bar NO Status Bar Style UIStatusBarStyleLightContent 在PLIST中查看基于控制器的状态栏否状态栏样式UIStatusBarStyleLightContent

In AppDelegate DidFinishLaunching 在AppDelegate中DidFinishLaunching

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [self.window setBackgroundColor:[UIColor whiteColor]];

In Each View Controller 在每个视图控制器中

- (UIStatusBarStyle) preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

This bug only occurs if your app is being scaled to fit the resolution of the newer devices. 如果您的应用程序正在缩放以适应新设备的分辨率,则只会出现此错误。

A quick fix (who knows whether this will even get addressed in 8.1) is to provide the proper resolution loading images in your app package. 快速修复(谁知道这是否会在8.1中得到解决)是在应用包中提供正确的解决方案加载图像。

From https://developer.apple.com/ios/human-interface-guidelines/graphics/launch-screen/ 来自https://developer.apple.com/ios/human-interface-guidelines/graphics/launch-screen/

For iPhone 7, iPhone 6s, iPhone 6:

750 x 1334 (@2x) for portrait
1334 x 750 (@2x) for landscape

For iPhone 7 Plus, iPhone 6s Plus, iPhone 6 Plus:

1242 x 2208 (@3x) for portrait
2208 x 1242 (@3x) for landscape

In my app, we only support portrait, so providing the 750x1334 and 1242x2208 fixed it. 在我的应用程序中,我们只支持肖像,因此提供750x1334和1242x2208修复它。

And just to confirm in case it wasn't obvious, you DO need to be using UIStatusBarStyleLightContent for your status bar style. 只是为了确认它不明显,你需要使用UIStatusBarStyleLightContent作为状态栏样式。

My app's status bar was working fine in iOS 7 using only the project/target settings: 我的应用程序的状态栏在iOS 7中仅使用项目/目标设置正常工作:

Status bar style = UIStatusBarStyleLightContent

and

View controller-based status bar appearance = NO

but in iOS 8 (iPhone 6 and iPhone 6 Plus simulators) the status bar was not showing up. 但在iOS 8(iPhone 6和iPhone 6 Plus模拟器)中,状态栏没有显示出来。 Changing View controller-based status bar appearance to YES and then adding: 将基于控制器的状态栏外观更改为YES,然后添加:

    // Objective C
    - (UIStatusBarStyle) preferredStatusBarStyle {
         return UIStatusBarStyleLightContent;
    }
    //Swift
    override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.LightContent
    }

to the ViewController resulted in seeing the white status bar again, but only after the initial root controller launches. 到ViewController导致再次看到白色状态栏,但仅在初始根控制器启动后。 During the initial launch the status bar remains black. 在初始启动期间,状态栏保持黑色。

A similar answer (currently voted as 2nd) has already posted, buy in the interests of keeping this post up-to-date, here is the Swift version. 一个类似的答案(目前被评为第二名)已经发布,为了保持这篇文章的最新信息而购买,这里是Swift版本。

  1. Add a row to your info.plist file called View controller-based status bar appearance and set its boolean value to NO . 在info.plist文件中添加一行,名为View controller-based status bar appearance ,并将其布尔值设置为NO

  2. In your AppDelegate.swift file, add the following method: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { UIApplication.sharedApplication().statusBarStyle = .LightContent return true } AppDelegate.swift文件中,添加以下方法: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { UIApplication.sharedApplication().statusBarStyle = .LightContent return true }

  3. I didn't need to do this step in order for it to work (ie do steps 1 and 2 and it might work). 我不需要执行此步骤以使其工作(即执行步骤1和2,它可能会起作用)。 If not, try adding the following method to each of your ViewControllers : 如果没有,请尝试将以下方法添加到每个ViewControllers

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

I hope this was helpful, 我希望这可以帮到你,

Loic 卢瓦克

  1. Open Info.plist 打开Info.plist
  2. Add new property called "View controller-based status bar appearance" (Boolean) and set its value to "NO" 添加名为“View controller-based status bar appearance”(布尔值)的新属性,并将其值设置为“NO”
  3. Add new property called "Status bar style" (String) and set its value to "Opaque black style" 添加名为“状态栏样式”(String)的新属性,并将其值设置为“不透明的黑色样式”

Done. 完成。

AppDelegatedidFinishLaunchingWithOptions:方法中添加以下行

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];

Step 1: Open the info.plist file of your app and set the UIViewControllerBasedStatusBarAppearance to NO 第1步:打开应用程序的info.plist文件,并将UIViewControllerBasedStatusBarAppearance设置为NO

Step 2: info.plist file of your app and set the "Status bar style" to UIStatusBarStyleLightContent 第2步:应用程序的info.plist文件,并将“状态栏样式”设置为UIStatusBarStyleLightContent

Could be problem with simulator. 可能是模拟器的问题。 Use this to override default status bar or status bar for a specific view controller. 使用此选项可覆盖特定视图控制器的默认状态栏或状态栏。

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.LightContent
} //This is swift code

I know it's bad style to override behaviour in a base class using a category, but this works and may be the quickest solution to fix it. 我知道使用类别覆盖基类中的行为是不好的方式,但这可行并且可能是解决它的最快解决方案。

Step #1: Ensure UIViewControllerBasedStatusBarAppearance or View controller-based status bar appearance is set to YES in your application plist file. 步骤1:确保应用程序plist文件中的UIViewControllerBasedStatusBarAppearanceView controller-based status bar appearance设置为YES

Step #2: Add the following code to your project: 步骤2:将以下代码添加到您的项目中:

@implementation UIViewController (StatusBarColorFix)

- (UIStatusBarStyle) preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

@end

A good fix for this is to use the new launch image nib support which gets used on the iPhone 6 models. 一个很好的解决方法是使用在iPhone 6模型上使用的新的启动图像笔尖支持。 It seems like there's just a bug in iOS 8 that means that the iPhone 6 models don't check the status bar style correctly when launching but it gets solved if you add in the launch nib. 似乎iOS 8中只有一个错误,这意味着iPhone 6型号在启动时不会正确检查状态栏样式,但如果添加启动笔尖则会解决。

As Aaron Wasserman pointed out you can also specify iPhone 6 & 6+ launch PNGs and that seems to fix the problem too, so long as you set them up right! 正如Aaron Wasserman指出你也可以指定iPhone 6和6+发布PNG,这似乎也解决了这个问题,只要你设置正确!

在Storyboard中选择根视图控制器并将状态栏类型设置为default

I have performed following steps and they worked for me quite well, should be working in iOS 8+ as well. 我已经执行了以下步骤,它们对我很有用,也应该在iOS 8+中工作。

1) Added property View controller-based status bar appearance => NO in Info.plist. 1)添加属性在Info.plist中查看基于控制器的状态栏外观 =>
2) Add following piece of code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions of AppDelegate.m 2)加入下列中的一段代码- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions AppDelegate.m

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [self.window setBackgroundColor:[UIColor redColor]]; // Change color as per need.

3) Override method in ViewController 3) ViewController覆盖方法

- (UIStatusBarStyle) preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

For swift 4 and iOS 11 适用于swift 4和iOS 11

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    application.statusBarStyle = .lightContent
    return true
}

Here is Apple Guidelines/Instruction about status bar/text color change. 以下是有关状态栏/文本颜色更改的Apple指南/说明

Here is - How to change status bar style: 这是 - 如何更改状态栏样式:

If you want to set status bar style, application level then set UIViewControllerBasedStatusBarAppearance to NO in your `.plist' file. 如果要设置状态栏样式,应用程序级别,请在“.plist”文件中将UIViewControllerBasedStatusBarAppearance设置为NO

Or programatically you can do from App Delegate: 或者以编程方式,您可以从App Delegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    application.statusBarStyle = .lightContent
    return true
}

if you wan to set status bar style, at view controller level then follow these steps: 如果您要在视图控制器级别设置状态栏样式,请按照下列步骤操作:

  1. Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file, if you need to set status bar style at UIViewController level only. 如果您只需要在UIViewController级别设置状态栏样式,请在.plist文件中将UIViewControllerBasedStatusBarAppearance设置为YES
  2. In the viewDidLoad add function - setNeedsStatusBarAppearanceUpdate 在viewDidLoad中添加函数setNeedsStatusBarAppearanceUpdate

  3. override preferredStatusBarStyle in your view controller. 覆盖视图控制器中的preferredStatusBarStyle。

- -

override func viewDidLoad() {
    super.viewDidLoad()
    self.setNeedsStatusBarAppearanceUpdate()
}

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

Set value of .plist according to status bar style setup level. 根据状态栏样式设置级别设置.plist的值。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM