Adding leftbarbuttonitem to UIImagePickerController

167 Views Asked by At

I have to customise UIImagePickerController (adding left bar button item and removing right bar button item) as follows:

UIImagePickerController

I tried to achieve this:

- (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;
    }
} 

But it is not happening. Help me to resolve it.

1

There are 1 best solutions below

0
On

According to Apple documentation: https://developer.apple.com/reference/uikit/uiimagepickercontroller

Important

The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.