Iphone 如何在UIImagePickerController中更改取消按钮标题?

Iphone 如何在UIImagePickerController中更改取消按钮标题?,iphone,ios,objective-c,uiimagepickercontroller,Iphone,Ios,Objective C,Uiimagepickercontroller,目前,我正在处理一个多语言应用程序,我想更改UIImagePickerController的取消、使用和重做按钮标题。我该怎么做?它将自动更改为设备语言 你不必为此担心。你也不能改变它的行为 诸如:MFMessageComposer、MFMailComposer、UIImagePicker等控件将自动将其默认控件文本更改为设备语言。将委托作为自身分配给imagepicker控制器,并添加以下代码: - (void)navigationController:(UINavigationControl

目前,我正在处理一个多语言应用程序,我想更改
UIImagePickerController
取消
使用
重做
按钮标题。我该怎么做?

它将自动更改为设备语言

你不必为此担心。你也不能改变它的行为


诸如:
MFMessageComposer
MFMailComposer
UIImagePicker
等控件将自动将其默认控件文本更改为设备语言。

将委托作为自身分配给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;
}

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

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

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

4) 在“本地化”部分添加所需的语言。

只需查找并更改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];
                }

            }
        }
    }

唯一好的解决办法是这里

//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];
}
//这是您的相机方法
-(无效)startCameraControllerUsingDelegate:(id)代表库:(BOOL)openGallery
{
如果([UIImagePickerController isSourceTypeAvailable:UIImagePickerController SourceTypeCamera]==否)
||(委托=零)
返回;
UIImagePickerController*cameraUI=[[UIImagePickerController alloc]init];
如果(openGallery){
cameraUI.sourceType=UIImagePickerController源类型照片库;
}否则{
cameraUI.sourceType=UIImagePickerControllerSourceTypeCamera;
}
cameraUI.allowsEditing=是;
//在此处设置您的委托类型UINavigationControllerDelegate!它将触发下面的函数!
cameraUI.delegate=代表;
[self-presentViewController:cameraUI动画:是完成:无];
}
//UINavigationControllerDelegate函数
-(void)导航控制器:(UINavigationController*)导航控制器将显示视图控制器:(UIViewController*)视图控制器已设置动画:(BOOL)已设置动画
{
//这就是神奇发生的地方!这会让按钮空着,不会破坏标题中心的位置!…或者给它你想要的字符串
viewController.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“样式:UIBarButtonItems样式普通目标:无操作:无];
}

如果设备语言为英语,而我当时想更改标题,我们如何才能实现这一点?选择器是嵌入式的,如果在不重新启动应用程序的情况下设置语言,这种方法将无法工作。