How to center a UIPopoverController and also without arrows

Short recipe here. This blog isn’t always about you… it’s about augmenting my memory! 😀


  UIViewController *contentController = [[UIViewController alloc] init]; // obviously your own...
    
  UIPopoverArrowDirection arrows;
  CGRect rectForWindow;
  BOOL centeredInWindow = YES;
    
  if (centeredInWindow) {
    rectForWindow = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2, 1, 1);
    arrows = 0;
  }
  else
  {
    // view being some view like a UIButton, that triggered the popup...
    rectForWindow = [self.view convertRect:view.frame fromView: view.superview];  // or whatever...
    arrows = UIPopoverArrowDirectionDown;  // or whatever...
  }

  self.popover = [[UIPopoverController alloc] initWithContentViewController:contentController];
  self.popover.delegate = self;
  
  // set your contentSize
  CGSize contentSize = (CGSize){320, 460};
  [self.popover setPopoverContentSize:contentSize];
  
  [self.popover presentPopoverFromRect:rectForWindow 
                                inView:self.view 
              permittedArrowDirections:arrows 
                              animated:YES];