I followed this thread to override -preferredStatusBarStyle
, but it isn't called.
Are there any options that I can change to enable it? (I'm using XIBs in my project.)
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
My app used all three:
UINavigationController
,UISplitViewController
,UITabBarController
, thus these all seem to take control over the status bar and will causepreferedStatusBarStyle
to not be called for their children. To override this behavior you can create an extension like the rest of the answers have mentioned. Here is an extension for all three, in Swift 4. Wish Apple was more clear about this sort of stuff.Tyson's answer is correct for changing the status bar color to white in
UINavigationController
.If anyone want's to accomplish the same result by writing the code in
AppDelegate
then use below code and write it insideAppDelegate's
didFinishLaunchingWithOptions
method.And don't forget to set the
UIViewControllerBasedStatusBarAppearance
toYES
in the .plist file, else the change will not reflect.Code
@serenn's answer above is still a great one for the case of UINavigationControllers. However, for swift 3 the childViewController functions have been changed to
vars
. So theUINavigationController
extension code should be:And then in the view controller that should dictate the status bar style:
In addition to serenn's answer, if you are presenting a view controller with a
modalPresentationStyle
(for example.overCurrentContext
), you should also call this on the newly presented view controller:Don't forget to also override the
preferredStatusBarStyle
in the presented view controller.An addition to Hippo's answer: if you're using a UINavigationController, then it's probably better to add a category:
That solution is probably better than switching to soon-to-be deprecated behaviour.
Most of the answers don't include good implementation of
childViewControllerForStatusBarStyle
method forUINavigationController
. According to my experience you should handle such cases as when transparent view controller is presented over navigation controller. In these cases you should pass control to your modal controller (visibleViewController
), but not when it's disappearing.