自定义后退按钮出现在UIImagePickerController上

时间:2012-11-15 20:12:27

标签: ios uinavigationbar back-button uiappearance

我使用以下代码在整个应用程序中自定义导航栏上的后退按钮:

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];

它很有效,除非我提供UIImagePickerController并在照片库中输入相册,后退按钮也是自定义后退按钮。如何取回图像选择器中的原始后退按钮?

3 个答案:

答案 0 :(得分:9)

 [[UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil] setBackButtonBackgroundImage:[UIImage imageNamed:@"blank-button"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

这是正确的方法

答案 1 :(得分:4)

尝试使用:

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

这应该将您的外观设置限制为仅列出的类,因此单独保留UIImagePickerController。

答案 2 :(得分:0)

1.对于swift和ios9(上面的答案会是这样的) -

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

2.如果要修改UINavigationBar的backIndicatorImage

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

3.如果你想修改backIndicatorTransitionMaskImage

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