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

后端 未结 6 2028
南笙
南笙 2021-01-12 19:28

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

6条回答
  •  盖世英雄少女心
    2021-01-12 19:36

    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)
    

提交回复
热议问题