Search code examples
iosuinavigationcontrolleruiimagepickercontrolleruinavigationitemsubclassing

Customizing navigation items of UIImagePickerController


I'm trying to change the navigation bar buttons of the UIImagePickerController. So far I have only managed to change the right bar button item ("Cancel" button):

- (void)navigationController:(UINavigationController *)navigationController         
       willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

       UINavigationBar *bar = navigationController.navigationBar;
       UINavigationItem *top = bar.topItem;
       top.title = @"Photos";
       UIImage *buttonImageCancel = [UIImage imageNamed:@"DoneBarButton.png"];
       UIButton *buttonCancel = [[UIButton alloc] initWithFrame:CGRectMake(0,5,55, 29)];
       [buttonCancel setBackgroundImage:buttonImageCancel forState:UIControlStateNormal];
       [buttonCancel addTarget:self action:@selector(imagePickerControllerDidCancel:) forControlEvents:UIControlEventTouchUpInside];
       [buttonCancel setTitle:@"Cancel" forState:UIControlStateNormal];
       [buttonCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
       [[buttonCancel titleLabel] setFont:[UIFont boldSystemFontOfSize:10]];
       UIBarButtonItem *barButtonCancel = [[UIBarButtonItem alloc] initWithCustomView:buttonCancel];
       [top setRightBarButtonItem:barButtonCancel];   }

But in the other view controllers (e.g. "Photo Library") the "Cancel" button is the old one again. Also, after switching back to the main picker view, the customized "Cancel" button is replaced by the standard one again. Does anyone know how to change those buttons? Subclassing? Thanks very much!


Solution

  • The method you implemented gets called only when you push the view Controller. If you want to make change in the whole picker than you can use category of Navigation Controller.