I\'m using UIPopoverPresentationController
to present popovers in an iOS app. I want to dim the background behind the popover when it comes up. How can I do thi
I just created my view controller, set the popover style and then presented it, setting the background color in the completion callback (because the containerView will be non-nil at that point). Works well with Swift 4+.
let myViewController: MyViewController = MyViewController()
myViewController.modalPresentationStyle = UIModalPresentationStyle.popover
if let presentationController: UIPopoverPresentationController = myViewController.popoverPresentationController {
presentationController.delegate = self.mainViewController
presentationController.sourceView = sourceView
presentationController.sourceRect = sourceRect
self.mainViewController.present(myViewController, animated: false, completion: {
presentationController.containerView?.backgroundColor = UIColor.white.withAlphaComponent(0.5)
})
}