可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
(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:)
回答1:
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.
From 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.
And just to confirm in case it wasn't obvious, you DO need to be using UIStatusBarStyleLightContent for your status bar style.
回答2:
So here is how I fixed it
In PLIST
View Controller Based Status Bar NO
Status Bar Style UIStatusBarStyleLightContent
In AppDelegate DidFinishLaunching
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
[self.window setBackgroundColor:[UIColor whiteColor]];
In Each View Controller
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
回答3:
My app's status bar was working fine in iOS 7 using only the project/target settings:
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:
// 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.
回答4:
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.
Add a row to your info.plist file called View controller-based status bar appearance and set its boolean value to NO.
In your AppDelegate.swift file, 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
}
I hope this was helpful,
Loic
回答5:
- 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"
Done.
回答6:
Add the following line in AppDelegate
's didFinishLaunchingWithOptions:
method
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];
回答7:
Step 1: Open the info.plist file of your app and set the UIViewControllerBasedStatusBarAppearance to NO
Step 2: info.plist file of your app and set the "Status bar style" to UIStatusBarStyleLightContent
回答8:
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
回答9:
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.
Step #2: Add the following code to your project:
@implementation UIViewController (StatusBarColorFix)
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
@end
回答10:
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.
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!
回答11:
In your Storyboard select your root view controller and set status bar type default
回答12:
I have performed following steps and they worked for me quite well, should be working in iOS 8+ as well.
1) Added property View controller-based status bar appearance => NO in Info.plist.
2) Add following piece of code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
of AppDelegate.m
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
[self.window setBackgroundColor:[UIColor redColor]]; // Change color as per need.
3) Override method in ViewController
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
回答13:
For swift 4 and iOS 11
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
application.statusBarStyle = .lightContent
return true
}
回答14:
Here is Apple Guidelines/Instruction about status bar/text color change.
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.
Or programatically you can do from 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:
- Set the
UIViewControllerBasedStatusBarAppearance
to YES
in the .plist
file, if you need to set status bar style at UIViewController level only.
In the viewDidLoad add function - setNeedsStatusBarAppearanceUpdate
override preferredStatusBarStyle in your view controller.
-
override func viewDidLoad() {
super.viewDidLoad()
self.setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Set value of .plist according to status bar style setup level.