OGeek|极客世界-中国程序员成长平台

标题: ios - 选择视频时是否可以更改 `UIImagePickerController` 的标题? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:45
标题: ios - 选择视频时是否可以更改 `UIImagePickerController` 的标题?

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

- (void)selectMediaFromUIImagePickerControllerSourceType)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 的标题显示为 Photos,请参见我附上的截图。

imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary and imagePicker.mediaTypes = @[(NSString *)kUTTypeMovie, (NSString *)kUTTypeVideo]

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

Default Photos App

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



Best Answer-推荐答案


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

添加UINavigationControllerDelegate

的委托(delegate)

Swift 3.0

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

Objective-C

- (void)navigationControllerUINavigationController *)navigationController willShowViewControllerUIViewController *)viewController animatedBOOL)animated{
    [viewController.navigationItem setTitle"Kirit Modi"];
}

查看输出:

enter image description here

关于ios - 选择视频时是否可以更改 `UIImagePickerController` 的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46599848/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4