Search code examples
ios8uipopovercontroller

Unwanted margin UIPopoverController


When I present my popover in a view and place it at the side of the view. There is always a small margin, causing the popover to not stick to the side.

UIViewController *vc =  [self getViewController:@"popover" fromStoryboard:@"Main"];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:vc];
[popover presentPopoverFromRect:CGRectMake(1100, 0, -65, 65)
                              inView:self.view
            permittedArrowDirections:UIPopoverArrowDirectionUp
                       animated:YES];
[vc setPreferredContentSize:CGSizeMake(300, 300)];

Example in simulator

How do I prevent this margin and show my popover sticking to the side of the view?

Thanks


Solution

  • I fixed this issue by adding my own UIPopoverBackgroundView implementation where I set my own contentview insets.

    + (UIEdgeInsets)contentViewInsets {
        return UIEdgeInsetsMake(-10, -10, -10, -10);
    }
    

    and adding this backgroundview to my popovercontroller

    [self.popover setPopoverBackgroundViewClass:[MyPopoverBackgroundView class]];