Reputation: 1897
I want darker background dim color for UIPopover
. I know this can be achieved by subclassing UIPopoverBackgroundView
as mentioned here but I am looking for any simpler way to do this.
P.S. I am using Objective C not Swift.
Upvotes: 9
Views: 5750
Reputation: 1557
Since the user is asking for an Obj C solution - use in the VC that's being displayed in the popover
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.popoverPresentationController.containerView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
}
Upvotes: 2
Reputation: 1144
Swift 4
I just came upon the same problem and found a solution similar to jimmyjudas.
In the viewController displayed as a popover:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.presentingViewController?.view.alpha = 0.3
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.presentingViewController?.view.alpha = 1
}
Upvotes: 16
Reputation: 141
UIPopover doesn't background property because it subclass of NSObject don't have customizing view property so you can change its content color -
UIPopoverController *popC = [[UIPopoverController alloc] initWithContentViewController:TestingPC];
[[[popC contentViewController] view] setBackgroundColor:[UIColor blackcolor]];
Upvotes: -1
Reputation: 151
Easiest method is to simply call self.view.alpha = 0.2
before presenting the popover and setting it back to 1.0 when the popover is dismissed.
Upvotes: 3