问题
Here's my implementation in a subclass of UIViewController
:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)
}
I tried putting it in AppDelegate initialisation code (using the passed in UIApplication instance), however the status bar is still black..
Is this a bug with iOS 8 or am I doing it wrong?
Note: I may be breaking someone's law's here by discussing ios 8.. Its a general problem that, when compiled doesn't work for ios 7 either.
Update: Still doesn't work, even with value in Info.plist and code in - didFinishLaunchingWithOptions
回答1:
You really should implement preferredStatusBarStyle
on your view controller(s):
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
回答2:
- Go to Info.plist file
- Hover on one of those lines and a (+) and (-) button will show up.
- Click the plus button to add new key Type in start with capital V and automatically the first choice will be View controller-based status bar appearance.
- Add that as the KEY.
- Set the VALUE to "NO"
- Go to you AppDelegate.swift
- Add the following code, inside the method
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)
return true
}
- DONE! Run your app and your status bar is now WHITE!
来源:https://stackoverflow.com/questions/24622960/swift-uiapplication-setstatusbarstyle-doesnt-work