Search code examples
ioscamerauiimagepickercontroller

Change ImagePicker from "Use Photo" to "Save Photo


I have a part in my app in which users can take a quick photo and save it to the camera roll. My only is that after the photo has been taken, it comes to the screen with the square cropper (i guess that's what it is) and then down the bottom it says "Retake" and "Use Photo". I want that Use Photo to say "Save Photo" (which is what it does anyway). Is there anyway to do this? Here's my code

- (IBAction)takePhoto:(UIButton *)sender {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

[self presentViewController:picker animated:YES completion:NULL];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
UIImageWriteToSavedPhotosAlbum(chosenImage, nil, nil, nil);
[picker dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

[picker dismissViewControllerAnimated:YES completion:NULL];
}

Solution

  • U can change cancel button to any title u want:

    1. Add UINavigationControllerDelegate delegate to your viewController that u will click the button and will show the camera
    2. Add the below codes in your viewController:

      - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
      
      [[UIApplication sharedApplication] setStatusBarHidden:YES];
      [self changeCancelToAnythingUWantOf:viewController andReplacementString:@"Your Replacement String"];
      

      }

      - (void)changeCancelToAnythingUWantOf:(UIViewController*)vc andReplacementString:(NSString*)title {
      
      for(UIView *subView in vc.view.subviews) {
       if ([subView isKindOfClass:[UIButton class]]) {
          UIButton *btn = (UIButton *)subView;
          if([btn.titleLabel.text isEqualToString:@"Cancel"]) {
              [btn setTitle:title forState:UIControlStateNormal];
              break;
          }
      }
      
       if (subView.subviews) {
          for (UIView *subSubView in subView.subviews) {
              if ([subSubView isKindOfClass:[UIButton class]]) {
                  UIButton *btn = (UIButton *)subSubView;
                  if([btn.titleLabel.text isEqualToString:@"Cancel"]) {
                      [btn setTitle:title forState:UIControlStateNormal];
                      break;
                  } 
              }
      
              if (subSubView.subviews) {
                  for (UIView *subSubSubView in subSubView.subviews) {
                      if ([subSubSubView isKindOfClass:[UIButton class]]) {
                          UIButton *btn = (UIButton *)subSubSubView;
                          if([btn.titleLabel.text isEqualToString:@"Cancel"]) {
                              [btn setTitle:title forState:UIControlStateNormal];
                              break;
                          } 
                      }
                  }
               }
             }
           }
         }
       }