Change UIPopoverView background + arrow color
I found the solution. Subclassing is not necessary anymore with iOS8! The background can be accessed and changed like this from within the tableview -> navigation -> popoverPresentationController
self.navigationController?.popoverPresentationController?.backgroundColor = UIColor.redColor()
More information about this in WWDC session 2014.
You can simply modify popover like this:
let popoverViewController = self.storyboard?.instantiateViewControllerWithIdentifier("popoverSegue") popoverViewController!.popoverPresentationController?.delegate = self popoverViewController!.modalPresentationStyle = .Popover let popoverSize = CGSize(width: 150, height: 60) popoverViewController!.preferredContentSize = popoverSize let popover = popoverViewController!.popoverPresentationController popover?.delegate = self popover?.permittedArrowDirections = .Up popover?.sourceView = self.view //change background color with arrow too! popover?.backgroundColor = UIColor.whiteColor() popover?.sourceRect = CGRect(x: self.view.frame.width, y: -10, width: 0, height: 0) presentViewController(popoverViewController!, animated: true, completion: nil)
Seems like that popoverPresentationController.backgroundColor no longer works in iOS13.
Popover arrows now appear to take on the color of the popover viewController's view.backgroundColor.
Here's the whole code for the demo below:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let sourceButton = sender as? UIButton, let popover = segue.destination.popoverPresentationController { popover.sourceView = sourceButton.superview popover.sourceRect = sourceButton.frame popover.permittedArrowDirections = [.left] popover.delegate = self segue.destination.preferredContentSize = CGSize(width: 100, height: 100) //popover.backgroundColor = sourceButton.tintColor //old way segue.destination.view.backgroundColor = sourceButton.tintColor //new way }}@IBAction func btnTap(_ sender: Any) { performSegue(withIdentifier: "popoverSegue", sender: sender)}func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle { return .none}