Search code examples
iosobjective-cios7uisearchdisplaycontrolleruistatusbar

preferredStatusBarStyle for native controllers


Since apple introduced UIViewControllerBasedStatusBarAppearance and preferredStatusBarStyle in iOS 7 I'm trying to understand whats best practice to change status bar color for built in view controller, like:

UIImagePickerController  
MFMailComposeViewController  
UISearchDisplayController  

for example, when using UISearchDisplayController, I want to change the status bar from light to dark when the search bar appears.
how can I do that? do I need to subclass UISearchDisplayController? maybe category?

and what about UIImagePickerController it has its own stack of view controllers, how can change the status bar style for all of them when presenting the photo picker?

until now I used the global why of

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];  

but now its all per-ViewController approach, so how would I modify controllers that are not mine?


Solution

  • Yes, you can subclass those classes to change the status bar appearance. According to UIImagePickerController, it's just a subclass of the UINavigationController, so, if you subclass and implement preferredStatusBarStyle in your subclass, all other view those appear on navigation will have the same status bar. Good Luck!