Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the opacity of the overlay behind UIPopoverPresentationController?

Tags:

ios

uikit

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?

like image 382
Tom Hamming Avatar asked Sep 21 '15 14:09

Tom Hamming


2 Answers

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)
like image 93
Carlos Chaguendo Avatar answered Nov 04 '22 01:11

Carlos Chaguendo


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];
like image 7
Jim75 Avatar answered Nov 04 '22 00:11

Jim75