选择视频时是否可以更改 UIImagePickerController 的标题?

Is is possible to change title of `UIImagePickerController`when choosing videos?

我打开了照片库来选择视频。这是我的代码:

- (void)selectMediaFrom:(UIImagePickerControllerSourceType)sourceType {
     UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = sourceType;
    imagePicker.delegate = self;
    //imagePicker.allowsEditing = YES;

    if (selectedMediaType == MediaVideos) {
        imagePicker.mediaTypes = @[(NSString *)kUTTypeMovie, (NSString *)kUTTypeVideo];
        if (sourceType == UIImagePickerControllerSourceTypeCamera) {
            imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
        }
    }
    else if (selectedMediaType == MediaPhotos) {
        imagePicker.mediaTypes = @[(NSString *)kUTTypeImage];
        if (sourceType == UIImagePickerControllerSourceTypeCamera) {
            imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
        }
    }

    if (IS_IPHONE) {
        [self presentViewController:imagePicker animated:TRUE completion:nil];
    }
    else {
        dispatch_async(dispatch_get_main_queue(), ^{

            [self setModalPresentationStyle:UIModalPresentationFormSheet];
            [self presentViewController:imagePicker animated:TRUE completion:nil];
        });
    }
}

而且它始终将 UIImagePickerController 的标题显示为 照片,请参阅我附上的屏幕截图。

但是,我已经打开 iPhone 默认 照片应用程序 并检查,显示视频文件夹:见下文

那为什么不显示 视频 标题?我们可以改变它吗?

是的,您可以更改您想要的导航标题。

添加UINavigationControllerDelegate

的代表

Swift 3.0

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool){
    viewController.navigationItem.title = "Kirit Modi"
}

Objective C

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    [viewController.navigationItem setTitle:@"Kirit Modi"];
}

查看输出:

谢谢。我能够适应我的情况。因为我从另一个 VC 以编程方式显示我的 ImagePicker,所以我不得不使用类似的代码。

我首先为演示文稿创建了一个变量 VC:

let imagePickerController = UIImagePickerController()

随后在演示 VC 中,我使用了:

Swift 4

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {

    // change title here to something other than default "Photo"
    imagePickerController.navigationBar.topItem?.title = "choose photo" 
}

效果很好。希望这对某人有所帮助。