I use the new (in iOS 7) UIPopoverController.backgroundColor parameter in my application to change the color of my popovers as necessary, but I find that using this parameter causes a βflashβ color change every time I open my popovers - after about half a second it starts with the default of translucent white and disappears to the color that I choose. This is undesirable; it should be only the color that I set when I open it.
The documentation states:
Use this property to adjust the background color of your popover. Changing the value of this property when a popover is visible causes an animated switch to a new color. The default value of this property is nil, which corresponds to the default background color.
However, even if I installed it when my application opens and does not install it again, it will flash every time you open any of the popovers.
I am open to using UIPopoverBackgroundView, but I'm not sure that it allows me to change the background color "on the fly", because it seems like a static solution for simply changing the style of all popovers in the application. Thank you in advance for any suggestions.
Change (code):
When my main view controller is loaded and ready to work with the rest of the user interface (this is one of many popover elements):
fileOptionsController = [[FileOptionsViewController alloc] initWithNibName:@"FileOptionsViewController" bundle:nil]; fileOptionsController.delegate = self; self.fileOptionsPopoverController = [[UIPopoverController alloc] initWithContentViewController:fileOptionsController]; [popoverControllers addObject:self.fileOptionsPopoverController];
After my popovers are initialized, I run this (still in the main initialization code) to test with a long delay between setting backgroundColor and the interaction (note: changing the alpha has no effect, it still happens when set to 1):
for (UIPopoverController *po in popoverControllers) { [po setBackgroundColor:[UIColor colorWithWhite:0.3f alpha:0.90f]]; }
This is then called when the user clicks a button to show a popover:
- (void)showPopover:(UIPopoverController *)popover from:(UIButton *)btn { [popover presentPopoverFromRect:CGRectMake(btn.frame.origin.x + 5.0f, btn.frame.origin.y - 1.0f, btn.frame.size.width, btn.frame.size.height) inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; }
Pretty straight forward. These are the only relevant places that are accessed by this or any popover, unless it is rejected if it is already showing.