我正在尝试在 iPhone 上使用 UIPopoverPresentationController 类呈现弹出窗口。 我需要在弹出框内显示导航 Controller 。所以我做了以下事情:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
viewController.preferredContentSize = size;
navigationController.modalPresentationStyle = UIModalPresentationPopover;
self.currentPopoverController = navigationController.popoverPresentationController;
self.currentPopoverController.backgroundColor = [UIColor commonApplicationBgColor];//My common app blue color
self.view.alpha = 0.7;
[self presentViewController:navigationController animated:YES completion:nil];
它工作正常,但箭头颜色与弹出导航栏背景颜色不同。我检查过它们使用相同的 [UIColor commonApplicationBgColor],但看起来箭头颜色更深。尝试为 self.currentPopoverController.backgroundColor 设置 alpha,但它仍然有错误的颜色。 请检查图像:
最佳答案
如果你不想要箭头那么你可以将 0 传递给 permittedarrowdirection
就像,
[popoverController presentPopoverFromRect:YOUR_RECT
inView:self.view
permittedArrowDirections:0
animated:YES];
更新:
你可以这样设置,
popover = [[UIPopoverController alloc] initWithContentViewController:contentViewController];
popover.backgroundColor = contentViewController.view.backgroundColor;
将背景颜色设置为 popovercontroller。
更新 2:
myPopoverViewController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:myPopoverViewController animated: YES completion: nil];
// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =
[myPopoverViewController popoverPresentationController];
presentationController.permittedArrowDirections =
UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight;
presentationController.sourceView = myView;
presentationController.sourceRect = sourceRect;
presentationController.backgroundColor = [UIColor grayColor]; //set your expacted color here.
希望对你有帮助
关于ios - UIPopoverPresentationController 无法设置箭头颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36673561/