Change UIImagePicker Navigation Bar style to blue

2020-08-05 10:56发布

All of my view has a blue navigation bar but when I want user to choose a photo, the UIImagePicker is black. I tried to set the navigation bar of UIImagePickerController to blue using UIBarStyleDefault but it does not work for me, the color is still black. I tried with other UIBarStyle like UIBarStyleBlack and UIBarStyleOpaque as well but it doesn't change the navigation bar of the picker anyway. Here is my code

    // Let the user choose a new photo.
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.navigationBar.barStyle = UIBarStyleDefault;
    [self presentModalViewController:imagePicker animated:YES];
    [imagePicker release];

3条回答
疯言疯语
2楼-- · 2020-08-05 11:00

Another way is using

- (void)navigationController:(UINavigationController *)navigationController 
  willShowViewController:(UIViewController *)viewController
                animated:(BOOL)animated {
navigationController.navigationBar.barStyle = UIBarStyleDefault;
}

that is an istance method of the UINavigationControllerDelegate protocol.

This will change the navigation bar style to blue.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-08-05 11:00

using the delegate to change it worked for me.

查看更多
我只想做你的唯一
4楼-- · 2020-08-05 11:02

I think there is no way to change it. So my solution is using Color Meter to get the color of the default navigation bar in color code: red code, blue code, green code. Then I use the method

imagePicker.navigationBar.tintColor = [UIColor colorWithRed:redCode green:greenCode blue:blueCode alpha:0.1];

UINavigationBar tintColor

UIColor Reference

查看更多
登录 后发表回答