【问题标题】:Is is possible to change title of `UIImagePickerController`when choosing videos?选择视频时是否可以更改 `UIImagePickerController` 的标题?
【发布时间】:2025-12-30 15:40:10
【问题描述】:

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

- (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 默认 照片应用程序 并检查,显示视频文件夹:见下文

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

【问题讨论】:

  • 在您的两个屏幕截图文件夹中的标题相同:Videos!你到底在问什么?你想达到什么目标还不是很清楚!
  • 我已经明确提到,我想更改屏幕标题。请参阅第一个屏幕截图。
  • 如果你只是想改变屏幕的标题,那么你不应该添加另一个屏幕截图四舍五入的视频!这让人困惑。你的问题应该是 how to change title of imagepickercontroller? 就是这样!

标签: ios objective-c uiimagepickercontroller video-capture photo-gallery


【解决方案1】:

是的,您可以更改所需的导航标题。

添加UINavigationControllerDelegate的代理

Swift 3.0

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

目标 C

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

查看输出:

【讨论】:

  • 谢谢。我能够适应我的情况。因为我从另一个 VC 以编程方式展示了我的 ImagePicker,所以我不得不使用类似的代码。我首先为展示的 VC 创建了一个变量:let imagePickerController = UIImagePickerController(),然后在展示的 VC 中,我使用了func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { imagePickerController.navigationBar.topItem?.title = "choose photo" }。它运作良好。希望这对某人有所帮助。
  • @PhontaineJudd 您也可以在答案中添加您的代码,以帮助大家。
【解决方案2】:

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

我首先为呈现的 VC 创建了一个变量:

let imagePickerController = UIImagePickerController()

然后在展示的 VC 中,我使用了:

斯威夫特 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" 
}

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

【讨论】:

    最近更新 更多