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 this? Is there an API for it somewhere, or am I going to have to overlay something on the main view when I present the popover?
in swift 3 you can access the overlay:
extension UIPopoverPresentationController {
var dimmingView: UIView? {
return value(forKey: "_dimmingView") as? UIView
}
}
After setting your controller to popover mode
controller.modalPresentationStyle = UIModalPresentationStyle.popover
controller.popoverPresentationController.dimmingView.backgroundColor = UIColor.black.withAlphaComponent(0.4)
Present via UIPopoverPresentationController and use its delegate method to change the containerView attributes:
- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController {
//
popoverPresentationController.containerView.backgroundColor = [UIColor colorWithWhite:0 alpha:.72];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With