5

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

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 并在照片库中输入相册时,后退按钮也是自定义的后退按钮。如何取回图像选择器中的原始后退按钮?

4

3 回答 3

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

这是正确的方法

于 2013-07-26T07:34:04.667 回答
4

尝试使用这个:

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

这应该将您的外观设置限制为仅列出您列出的类,因此不理会 UIImagePickerController。

于 2012-11-15T20:21:39.147 回答
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
于 2016-03-17T11:18:00.607 回答