When I present the ImagePickerController the statusBar text color is still bla
I had the same problem having to manage the application runned under different iOS versions.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if(IS_IOS8_AND_UP) {
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
} else {
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
}
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];
The, in delegate:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
/* Cancel button color */
_imagePicker.navigationBar.tintColor = <custom_color>
/* Status bar color */
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
I was facing a similar problem and I found the cleanest way to solve it was to override preferredStatusBarStyle
in an extension of UIImagePickerController
like so. This principal can be applied to third party libraries nicely.
extension UIImagePickerController {
open override var preferredStatusBarStyle: UIStatusBarStyle {
if isLightTheme() {
return .default // black text
}
return .lightContent // white text
}
}
isLightTheme()
is simply a function to determine whether the NavigationBar in that controller is a light or dark colour.
Just three steps:
1: Add UINavigationControllerDelegate
,UIImagePickerControllerDelegate
to your
@interface yourController ()<>
2: imagePickerController.delegate = self;
3:
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
This is the quickest solution I could think of. Create the following category:
@implementation UIImagePickerController (LightStatusBar)
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
@end
Using the answers above the following worked for me:
Implement
UINavigationControllerDelegate, UIImagePickerControllerDelegate
to your UIViewController
and set
imagePickerController.delegate = self;
Add the following method:
-(void) navigationController: (UINavigationController *) navigationController willShowViewController: (UIViewController *) viewController animated: (BOOL) animated {
navigationController.navigationBar.barStyle = UIBarStyleBlack;
}
In Swift and iOS 9, setStatusBarStyle
is deprecated. You could subclass the controller.
private final class LightStatusImagePickerController: UIImagePickerController {
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .lightContent
}
}