我在 UIPopoverController 中使用 UIImagePickerController 仅从相册中选择图像。当我在运行 iOS 8 的设备上启动应用程序时,弹出窗口右上角的取消按钮通常如下所示:
But when I launch the app on device running iOS 7, the Cancel button disappeared:
我用来显示选择器的代码:
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];
如何在 iOS7 上显示“取消”按钮?我的应用程序设计不允许用户通过点击弹出窗口视图之外的任何位置来关闭弹出窗口。
谢谢。
@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{
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)