How to change cancel button title in UIImagePickerController?

前端 未结 6 1495
再見小時候
再見小時候 2021-01-15 06:46

Currently I\'m working on a multi-language application and I want to change the Cancel ,Use and Retake button titles of the UIIm

相关标签:
6条回答
  • 2021-01-15 07:01

    Only good solution is here...

    //this is your camera method
    - (void)startCameraControllerUsingDelegate:(id<UIImagePickerControllerDelegate, UINavigationControllerDelegate>)delegate gallery:(BOOL)openGallery
    {
        if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
            || (delegate == nil))
            return;
    
        UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
        if (openGallery) {
            cameraUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        } else {
            cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
        }
    
        cameraUI.allowsEditing = YES;
        //set your delegate type UINavigationControllerDelegate here! It will trigger function bellow!
        cameraUI.delegate = delegate;
    
        [self presentViewController:cameraUI animated:YES completion:nil];
    }
    
    //UINavigationControllerDelegate function
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        //this is where magic happends! This leaves button empty and it will not ruin title center position!... or give it your desired string
        viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    }
    
    0 讨论(0)
  • 2021-01-15 07:02

    Just find and change text of UIButton

    -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
        {
            for (UIView *v in viewController.view.subviews)
            {
                if ([v isKindOfClass:[NSClassFromString(@"CMKBottomBar") class]])
                {
                    SEL se = NSSelectorFromString(@"cancelButton");
    
                    if ([v respondsToSelector:se])
                    {
                        UIButton *cancelButton =  [v performSelector:se];
                        [cancelButton setTitle:@"New title" forState:UIControlStateNormal];
                    }
    
                }
            }
        }
    
    0 讨论(0)
  • 2021-01-15 07:13

    It'll be automatically changed to device language.

    You don't need o worry about this. Also you can't change it's behavior.

    Controls like: MFMessageComposer, MFMailComposer, UIImagePicker etc. Will change it's default controls text to device language automatically.

    0 讨论(0)
  • 2021-01-15 07:16

    My problem is solved by using custom overlay class.

    self.picker = [[UIImagePickerController alloc] init];
    self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
    self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    self.picker.showsCameraControls = NO;
    self.picker.navigationBarHidden = YES;
    self.picker.toolbarHidden = YES;
    self.picker.wantsFullScreenLayout = YES;
    
    // Insert the overlay
    self.overlay = [[OverlayViewController alloc] initWithNibName:@"Overlay" bundle:nil];
    self.overlay.pickerReference = self.picker;
    self.picker.cameraOverlayView = self.overlay.view;
    self.picker.delegate = self.overlay;
    
    [self presentModalViewController:self.picker animated:NO];
    
    0 讨论(0)
  • 2021-01-15 07:17

    Just add needed localizations in your project:
    1) Select project file;
    2) Select your project in "Project and Targets" list;
    3) Select "Info" (in top part of screen);
    4) Add needed languages in "Localizations" section.

    0 讨论(0)
  • 2021-01-15 07:17

    Assign delegate as self to your imagepicker controller and add the following code :

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
         UINavigationItem *ipcNavBarTopItem;
    
        // add done button to right side of nav bar
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@\"Done\"
                                style:UIBarButtonItemStylePlain 
                                target:self 
                                action:@selector(saveImages:)];
    
        UINavigationBar *bar = navigationController.navigationBar;
       [bar setHidden:NO];
           ipcNavBarTopItem = bar.topItem;
           ipcNavBarTopItem.title = @\"Pick Images\";
       ipcNavBarTopItem.rightBarButtonItem = doneButton;
    }
    
    0 讨论(0)
提交回复
热议问题