Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change arrow color for popover created from storyboard in Swift

Tags:

ios

swift

popover

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.

like image 811
horothesun Avatar asked Nov 09 '22 16:11

horothesun


1 Answers

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)
like image 145
CedricSoubrie Avatar answered Nov 14 '22 23:11

CedricSoubrie