Customized back button appears on UIImagePickerCon

2019-02-17 13:26发布

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?

3条回答
做自己的国王
2楼-- · 2019-02-17 14:05

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.

查看更多
别忘想泡老子
3楼-- · 2019-02-17 14:05

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
查看更多
淡お忘
4楼-- · 2019-02-17 14:20
 [[UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil] setBackButtonBackgroundImage:[UIImage imageNamed:@"blank-button"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

this is the correct way

查看更多
登录 后发表回答