状态栏显示黑色文本,仅适用于 iPhone 6 iOS 8 模拟器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25869178/
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
Status Bar showing black text, only on iPhone 6 iOS 8 simulator
提问by Mohamed Hafez
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. 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. Any ideas what is going on?
我正在尝试将我的 iOS 7 应用程序转换为 Xcode 6 GM 中的 iOS 8,当我在 iPhone 5s 或更低版本的 iOS 8 模拟器上运行它时,一切正常,但在 iPhone 6 和 6 Plus 模拟器上,状态栏有黑色文本而不是白色,就像其他任何地方一样。我已经通过 Xcode 将 Info.plist UIStatusBarStyle 设置为“透明黑色样式(alpha 为 0.5)”,这似乎在其他任何地方都具有预期的效果。任何想法发生了什么?
(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:)
(我还没有接触任何故事板,这有什么关系吗?我希望我能把它推迟一段时间:)
采纳答案by Aaron Wasserman
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 用于您的状态栏样式。
回答by Taylor Pierce
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;
}
回答by Tony Adams
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. Changing View controller-based status bar appearance to YES and then adding:
但是在 iOS 8(iPhone 6 和 iPhone 6 Plus 模拟器)中,状态栏没有出现。将基于视图控制器的状态栏外观更改为 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. During the initial launch the status bar remains black.
到 ViewController 导致再次看到白色状态栏,但只有在初始根控制器启动之后。在初始启动期间,状态栏保持黑色。
回答by Loic Verrall
A similar answer (currently voted as 2nd) has already posted, buy in the interests of keeping this post up-to-date, here is the Swiftversion.
一个类似的答案(目前投票为 2nd)已经发布,为了让这篇文章保持最新而购买,这里是Swift版本。
Add a row to your info.plist file called View controller-based status bar appearanceand set its boolean value to NO.
In your AppDelegate.swiftfile, add the following method:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { UIApplication.sharedApplication().statusBarStyle = .LightContent return true }
I didn't need to do this step in order for it to work (i.e. do steps 1 and 2 and it might work). If not, try adding the following method to each of your ViewControllers:
override func preferredStatusBarStyle() -> UIStatusBarStyle { return UIStatusBarStyle.LightContent }
在 info.plist 文件中添加一行名为View controller-based status bar appearance并将其布尔值设置为NO。
在您的AppDelegate.swift文件中,添加以下方法:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { UIApplication.sharedApplication().statusBarStyle = .LightContent return true }
我不需要执行此步骤才能使其正常工作(即执行第 1 步和第 2 步,它可能会起作用)。如果没有,请尝试将以下方法添加到您的每个ViewControllers:
override func preferredStatusBarStyle() -> UIStatusBarStyle { return UIStatusBarStyle.LightContent }
I hope this was helpful,
我希望这可以帮到你,
Loic
洛伊克
回答by José
- Open Info.plist
- Add new property called "View controller-based status bar appearance" (Boolean) and set its value to "NO"
- Add new property called "Status bar style" (String) and set its value to "Opaque black style"
- 打开 Info.plist
- 添加名为“基于视图控制器的状态栏外观”(布尔值)的新属性并将其值设置为“NO”
- 添加名为“状态栏样式”(字符串)的新属性并将其值设置为“不透明黑色样式”
Done.
完毕。
回答by Kakashi
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
回答by Teja Kumar Bethina
Add the following line in AppDelegate
's didFinishLaunchingWithOptions:
method
在AppDelegate
的didFinishLaunchingWithOptions:
方法中添加以下行
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];
回答by Saqib Omer
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
回答by Sandy Chapman
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 步:确保UIViewControllerBasedStatusBarAppearance
或在您的应用程序 plist 文件中View controller-based status bar appearance
设置为YES
。
Step #2: Add the following code to your project:
第 2 步:将以下代码添加到您的项目中:
@implementation UIViewController (StatusBarColorFix)
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
@end
回答by CMash
A good fix for this is to use the new launch image nib support which gets used on the iPhone 6 models. 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.
一个很好的解决方法是使用 iPhone 6 机型上使用的新启动图像笔尖支持。似乎 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,这似乎也可以解决问题,只要您正确设置它们即可!