如何更改取消按钮标题中的UIImagePickerController?(How to change

2019-09-02 05:33发布

目前我正在一个多语言的应用程序,我想改变CancelUseRetake的按钮标题UIImagePickerController 。 我怎样才能做到这一点?

Answer 1:

我的问题是通过使用自定义覆盖类解决。

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];


Answer 2:

只需添加所需的本地化在您的项目:
1)选择工程文件;
2)在“项目和目标”列表中选择您的项目;
3)选择“信息”(在屏幕的顶部部分);
4)在“本地化”部分添加需要的语言。



Answer 3:

它会自动转换为设备语言。

你不需要这个Ø担心。 此外,你不能改变它的行为。

控制喜欢: MFMessageComposerMFMailComposerUIImagePicker等都会发生变化,将自动默认控件文本的设备语言。



Answer 4:

指定委托作为自我的imagepicker控制器并添加以下代码:

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


Answer 5:

这是所有一堆垃圾。 只有很好的解决办法是在这里...

//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];
}


Answer 6:

只要找到和改变的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];
                }

            }
        }
    }


文章来源: How to change cancel button title in UIImagePickerController?