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
Note that when using the
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
solutionbe sure to go to your plist and set "View controller-based status bar appearance" to YES. If its NO it will not work.
If anyone is using a Navigation Controller and wants all of their navigation controllers to have the black style, you can write an extension to UINavigationController like this in Swift 3 and it will apply to all navigation controllers (instead of assigning it to one controller at a time).
If your viewController is under UINavigationController.
Subclass UINavigationController and add
ViewController's
preferredStatusBarStyle
will be called.If someone run into this problem with UISearchController. Just create a new subclass of UISearchController, and then add code below into that class:
Here's my method for solving this.
Define a protocol called AGViewControllerAppearance.
AGViewControllerAppearance.h
Define a category on UIViewController called Upgrade.
UIViewController+Upgrade.h
UIViewController+Upgrade.m
Now, it's time to say that you're view controller is implementing the AGViewControllerAppearance protocol.
Example:
Of course, you can implement the rest of the methods (showsStatusBar, animatesStatusBarVisibility, prefferedStatusBarAnimation) from the protocol and UIViewController+Upgrade will do the proper customization based on the values provided by them.
For anyone using a UINavigationController:
The
UINavigationController
does not forward onpreferredStatusBarStyle
calls to its child view controllers. Instead it manages its own state - as it should, it is drawing at the top of the screen where the status bar lives and so should be responsible for it. Therefor implementingpreferredStatusBarStyle
in your VCs within a nav controller will do nothing - they will never be called.The trick is what the
UINavigationController
uses to decide what to return forUIStatusBarStyleDefault
orUIStatusBarStyleLightContent
. It bases this on itsUINavigationBar.barStyle
. The default (UIBarStyleDefault
) results in the dark foregroundUIStatusBarStyleDefault
status bar. AndUIBarStyleBlack
will give aUIStatusBarStyleLightContent
status bar.TL;DR:
If you want
UIStatusBarStyleLightContent
on aUINavigationController
use: