5

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.

Zouhair Sassi
  • 1,403
  • 1
  • 13
  • 30
horothesun
  • 427
  • 1
  • 6
  • 15
  • 3
    Set the background color in `prepareForSegue`. Like this `segue.destinationViewController.popoverPresentationController.backgroundColor`. – gabbler Apr 27 '16 at 08:11
  • It works for me, thank you very much! ;) – horothesun Apr 27 '16 at 08:17
  • 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 Feb 23 '18 at 09:17

2 Answers2

1

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)
CedricSoubrie
  • 6,657
  • 2
  • 39
  • 44
0

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

override func viewDidLoad()
{
    super.viewDidLoad()
    popoverPresentationController?.backgroundColor = view.backgroundColor
}
odyth
  • 4,324
  • 3
  • 37
  • 45