Lorsque je présente le ImagePickerController la couleur du text statusBar est toujours noir, comment faire comme ça?
Juste trois étapes:
1: Ajoutez UINavigationControllerDelegate
, UIImagePickerControllerDelegate
à votre
@interface yourController ()<>
2: imagePickerController.delegate = self;
3:
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; }
J'ai eu le même problème à gérer l'application exécutée sous différentes versions d'iOS .
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];
Le, en délégué:
- (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]; }
Dans Swift et iOS 9, setStatusBarStyle
est obsolète. Vous pourriez sous-classr le controller.
private final class LightStatusImagePickerController: UIImagePickerController { override func preferredStatusBarStyle() -> UIStatusBarStyle { return .LightContent } }
Solution rapide en écrivant une extension pour UIImagePickerController:
extension UIImagePickerController { convenience init(navigationBarStyle: UIBarStyle) { self.init() self.navigationBar.barStyle = navigationBarStyle } }
Ensuite, vous pouvez définir la couleur lors de l'initialisation:
let picker = UIImagePickerController(navigationBarStyle: .black) // black bar -> white text
Alternative (inspirée par la réponse de folse ): Lorsque vous initialisez le UIImagePickerController normalement, faites de cette class le délégué ( picker.delegate = self
) et implémentez cette fonction:
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) { if navigationController is UIImagePickerController { // check just to be safe navigationController.navigationBar.barStyle = .black // black bar -> white text } }
En utilisant les réponses ci-dessus, les choses suivantes ont fonctionné pour moi:
Implémentez UINavigationControllerDelegate, UIImagePickerControllerDelegate
sur votre UIViewController
et définissez
imagePickerController.delegate = self;
Ajoutez la méthode suivante:
-(void) navigationController: (UINavigationController *) navigationController willShowViewController: (UIViewController *) viewController animated: (BOOL) animated { navigationController.navigationBar.barStyle = UIBarStyleBlack; }
C'est la solution la plus rapide à laquelle je puisse penser. Créez la catégorie suivante:
@implementation UIImagePickerController (LightStatusBar) - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } @end