Search code examples
iphoneobjective-ccocoa-touchuipopovercontrolleruipopover

Make Popover Background Black in Interface Builder


I've successfully hooked up several popover views in interface builder. I've tried to make the background black by setting the view background color to black, but I am still getting a white arrow on the popover itself and white artifacts on the 4 rounded corners.

Please see the screenshot.

enter image description here

What can I do to make the background totally black in interface builder?

I appreciate the answer below but I still can't quite get it to work - here is my code:

// Show the satellite Ephemeris
    if ( itemIndex == 1 ) {

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            NSLog(@"This is an iPad - Creating popover!");
            EphemerisDataView *ephemView = [[EphemerisDataView alloc] init];
            UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:ephemView];
            [popOver setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
            [popOver.popoverBackgroundViewClass setTintColor:[UIColor blackColor]];
            CGSize size = CGSizeMake(320, 480); // size of view
            popOver.popoverContentSize = size;
            [popOver presentPopoverFromRect:self.popOverAnchor.bounds inView:self.view
                             permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

        }
        else {
            NSLog(@"This is not an iPad - Performing segue...");
            // Show the next view
            [self performSegueWithIdentifier:@"Ephemeris" sender:self];
        }
    }

Solution

  • Do it like this:

            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    
                NSLog(@"This is an iPad - Creating popover!");
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName: @"MainStoryboard_iPad" bundle:[NSBundle mainBundle]];
                EphemerisDataView *ephemView = [storyboard instantiateViewControllerWithIdentifier:@"EphemerisDataView"];
                UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:ephemView];
                self.customPopoverController = popOver;
                [popOver setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
                [popOver.popoverBackgroundViewClass setTintColor:[UIColor blackColor]];
                popOver.delegate = self;
                CGSize size = CGSizeMake(320, 480); // size of view
                popOver.popoverContentSize = size;
                [popOver presentPopoverFromRect:self.popOverAnchor.bounds inView:self.popOverAnchor
                                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    
            }
            else {
                NSLog(@"This is not an iPad - Performing segue...");
                // Show the next view
                [self performSegueWithIdentifier:@"Ephemeris" sender:self];
            }