5
votes

I'm trying to change the default popover arrow color for a popover defined as a storyboard segue (not built programmatically) from a button. The following picture shows the white default popover arrow:

enter image description here

When I add

navigationController?.popoverPresentationController?.backgroundColor = myNavBarColor

to the viewWillAppear method of the UIViewController presented in the popover, the result is the following:

enter image description here

Defining a new UIPopoverBackgroundView class for the UIPopoverPresentationController during the prepareForSegue method of the main UIViewController is "too late".

I hope there'll be a simple fix (with the same storyboard segue as popover) for such a common issue.

2
Set the background color in prepareForSegue. Like this segue.destinationViewController.popoverPresentationController.backgroundColor. - gabbler
It works for me, thank you very much! ;) - horothesun
Note that I first had to set segue.destination.modalPresentationStyle = .popover, otherwise segue.destination.popoverPresentationController would be nil. Apart from that, the solutions works fine. - iStefo

2 Answers

1
votes

Set the background color of the popoverPresentationController of your viewController :

let viewController = YOUR_VIEW_CONTROLLER
viewController.modalPresentationStyle = .popover
if let presentation = viewController.popoverPresentationController {
    presentation.backgroundColor = UIColor.white
}
present(viewController, animated: true, completion: nil)
0
votes

You can also set it inside the view that will be housed inside the popoverPresentationController

override func viewDidLoad()
{
    super.viewDidLoad()
    popoverPresentationController?.backgroundColor = view.backgroundColor
}