How to change cancel button title in UIImagePickerController?

前端 未结 6 1546
再見小時候
再見小時候 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)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];
    }
    

提交回复
热议问题