I have light top bar colors in my app, because the navigation bar is dark brown:
When I tap search (Keresés here), the following code sets the top bar color to dark content:
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
So it looks like this:
But when I type something into the field, then scroll the results list, the keyboard dismisses and the top bar is reverted to white. How can I prevent this?
In iOS 7, the status bar style is, by default, determined by the return value of the UIViewController
method -preferredStatusBarStyle
. The default implementation of this method returns UIStatusBarStyleDefault
.
Setting the info.plist key UIViewControllerBasedStatusBarAppearance
to the value of NO
returns to the pre-iOS 7 style of taking the status bar appearance from the shared UIApplication
object
To fix this you have two options:
1) Implement the -preferredStatusBarStyle
method in all your view controllers that want the status bar style to be non-default
2) Add the key "View controller-based status bar appearance" (UIViewControllerBasedStatusBarAppearance
) to your info.plist file and set its value to NO