Customized back button appears on UIImagePickerController
Asked Answered
M

3

5

I use the following code to customize the back button on the navigation bar throughout my application:

UIImage *backButton = [[UIImage imageNamed:@"backButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *backButtonOn = [[UIImage imageNamed:@"backButton_on"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton
                                                  forState:UIControlStateNormal
                                                barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonOn
                                                  forState:UIControlStateHighlighted
                                                barMetrics:UIBarMetricsDefault];

It's working great except when I present a UIImagePickerController and enter an album in the photo library the back button is also the customized back button. How can I get back the original back button in the image picker?

Michamichael answered 15/11, 2012 at 20:12 Comment(0)
S
4

Try using this:

    [[UINavigationBar appearanceWhenContainedIn:[YourClassThatsNotAUIImagePicker class], nil] setBackButtonBackgroundImage:someOtherImage forBarMetrics:UIBarMetricsDefault];

That should limit your appearance setting to only the classes you list and therefore leave the UIImagePickerController alone.

Scarce answered 15/11, 2012 at 20:21 Comment(1)
I solved the problem by creating a custom UINavigationBar subclass and used that in my navigation controller. Then I used the suggested [UINavigationBar appearanceWhenContainedIn:[MyNavigationBar class], nil] method. This way I only had to add my navigation bar class. Was a quick solution, thanks.Michamichael
O
9
 [[UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil] setBackButtonBackgroundImage:[UIImage imageNamed:@"blank-button"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

this is the correct way

Overcheck answered 26/7, 2013 at 7:34 Comment(1)
Definitely the best answer here.Bonaventure
S
4

Try using this:

    [[UINavigationBar appearanceWhenContainedIn:[YourClassThatsNotAUIImagePicker class], nil] setBackButtonBackgroundImage:someOtherImage forBarMetrics:UIBarMetricsDefault];

That should limit your appearance setting to only the classes you list and therefore leave the UIImagePickerController alone.

Scarce answered 15/11, 2012 at 20:21 Comment(1)
I solved the problem by creating a custom UINavigationBar subclass and used that in my navigation controller. Then I used the suggested [UINavigationBar appearanceWhenContainedIn:[MyNavigationBar class], nil] method. This way I only had to add my navigation bar class. Was a quick solution, thanks.Michamichael
A
0

1.for swift and ios9(the above answer will be like) --

    UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UIImagePickerController.self]).setBackButtonBackgroundImage(UIImage(named: "blank-button"), forState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)

2.if you want to modify backIndicatorImage of UINavigationBar

UINavigationBar.appearanceWhenContainedInInstancesOfClasses([UIImagePickerController.self]).backIndicatorImage = UIImage(named: "backButton")//or nil

3.if you want to modify backIndicatorTransitionMaskImage

UINavigationBar.appearanceWhenContainedInInstancesOfClasses([UIImagePickerController.self]).backIndicatorTransitionMaskImage =UIImage(named: "backButton")// nil
Assimilation answered 17/3, 2016 at 11:18 Comment(1)
UINavigationBar appearance not working when contained in UIImagePickerController. UIBarButtonItem works ok.Wideranging

© 2022 - 2024 — McMap. All rights reserved.