将leftbarbuttonitem添加到UIImagePickerController

时间:2016-12-19 19:41:09

标签: ios iphone uinavigationcontroller uiimagepickercontroller

我必须自定义UIImagePickerController(添加左栏按钮项并删除右栏按钮项),如下所示:

UIImagePickerController

我试图实现这个目标:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if([navigationController isKindOfClass:[UIImagePickerController class]]) {
        [viewController.navigationItem setTitle:@"Gallery"];
        UINavigationBar *bar = navigationController.navigationBar;             
        UINavigationItem *top = bar.topItem;
        UIBarButtonItem *leftBarNuttonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"CancelIcon"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissImagePickerView)];
        top.rightBarButtonItem = nil;
        top.leftBarButtonItem = leftBarNuttonItem;
    }
} 

但它没有发生。帮我解决一下。

1 个答案:

答案 0 :(得分:0)

根据Apple文档:https://developer.apple.com/reference/uikit/uiimagepickercontroller

  

重要

     

UIImagePickerController类仅支持纵向模式。这个   class旨在按原样使用,不支持子类化。   此类的视图层次结构是私有的,不得修改,   除了一个例外。您可以为自定义视图分配   cameraOverlayView属性并使用该视图来显示其他内容   信息或管理相机界面之间的交互   和你的代码。