Reputation: 37581
I'm using a UISearchController and adding its search bar to a table view controller's header:
The issues I'm facing is that when the user starts to type into the search bar, making it the first responder, then the status bar style is reverting to the .Default:
I'm using preferredStatusBarStyle()
to set the style in the view controller. If instead I use the info.plist to set the style and additionally set the 'View Controller Based Status Appearance' key to NO, then the style stays as Light.
However it is not an option to set the 'View Controller Based Status Appearance' key to NO as I have some VCs that require the default style and some that require the light style.
I tried resetting the style to light on a search bar delegate method (which gets invoked when it becomes first responder) i.e.:
func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool
{
UIApplication.sharedApplication().statusBarStyle = .LightContent
self.setNeedsStatusBarAppearanceUpdate()
return true
}
But that didn't work either.
Any suggestions?
Upvotes: 4
Views: 843
Reputation: 3131
Update for SWIFT 3.0
When a navigation controller is being called:
UIApplication.shared.statusBarStyle = .lightContent
(on viewDidLoad)
+
set View controller-based status bar appearance = NO
on info.plist
Upvotes: 0
Reputation: 37581
I don't know if there's another way, but I solved it by implementing a UISearchController derived class and using that instead:
class MySearchController : UISearchController
{
// various init overrides ...
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
}
Or if a navigation controller is being used then this will prevent preferredStatusBarStyle() from being called, in which case use this instead:
UIApplication.sharedApplication().statusBarStyle = .LightContent
AND
Make sure in the info.plist "View controller-based status bar appearance" is set to NO.
Upvotes: 3