简体   繁体   English

UIPopoverController中的UIImagePickerController在iOS7上不显示“取消”按钮

[英]UIImagePickerController inside UIPopoverController doesn't show Cancel button on iOS7

I'm using UIImagePickerController inside a UIPopoverController to select image just from photo albums. 我在UIPopoverController中使用UIImagePickerController来从相册中选择图像。 When I launch app on device running iOS 8, the Cancel button on the top right of the pop over appeared normally like this: 当我在运行iOS 8的设备上启动应用程序时,弹出窗口右上角的取消按钮通常如下所示:

在此输入图像描述

But when I launch the app on device running iOS 7, the Cancel button disappeared: 但是当我在运行iOS 7的设备上启动应用程序时,“取消”按钮消失了: 在此输入图像描述

The code I used to show the picker: 我用来显示选择器的代码:

    UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
    [pickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    pickerController.delegate = self;

    _popOver = [[UIPopoverController alloc] initWithContentViewController:pickerController];
    _popOver.delegate = self;

    pickerController.navigationBar.tintColor = [UIColor redColor];//Cancel button text color
    [pickerController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}];// title color

    if (isImage) {
        [pickerController setMediaTypes:@[(NSString*)kUTTypeImage]];
    } else
        [pickerController setMediaTypes:@[(NSString*)kUTTypeMovie]];
    [_popOver presentPopoverFromRect:CGRectMake(1024/2, 768/2, 1, 1) inView:self.view permittedArrowDirections:0 animated:YES];

What can I do to show that Cancel button on iOS7? 我该怎么做才能在iOS7上显示“取消”按钮? My app design doesn't allow user to dismiss the popover by tapping anywhere outside the popover view. 我的应用程序设计不允许用户通过点击弹出窗口视图外的任何位置来关闭弹出窗口。

Thank you. 谢谢。

@JozoL Write the Below Code this works @JozoL编写下面这段代码

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

        UINavigationItem *pickerNavBarTopItem;
        // add done button to right side of nav bar
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
                                                                       style:UIBarButtonItemStylePlain
                                                                      target:self
                                                                      action:@selector(doSomething)];

        UINavigationBar *bar = navigationController.navigationBar;
        [bar setHidden:NO];
        pickerNavBarTopItem = bar.topItem;
        pickerNavBarTopItem.rightBarButtonItem = doneButton;
    }
    -(void)doSomething{

    }

对于swift2.x,您可以尝试下面的代码,它适合我

pickerController.navigationBar.tintColor = UIColor.blueColor()

In my case, UIImagePickerController was not showing its cancel button . 在我的例子中, UIImagePickerController没有显示其取消按钮。 So I tried adding this line to code: 所以我尝试将此行添加到代码中:

pickerController.navigationBar.barStyle = UIBarStyleDefault;

And this worked for me.Try setting color of Cancel button like this 这对我有用。试试这样设置取消按钮的颜色

 pickerController.navigationBar.tintColor = [UIColor blackColor];

Try using this code and let me know if it helps you. 尝试使用此代码并告诉我它是否对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM