Search code examples
objective-ciosuiviewcontrollerios6uipopovercontroller

Where to set the size of a view controller presented in a popover?


Based on Apple's sample code, my app is presenting a view controller in a popover, which is trigged by a bar button:

- (IBAction)configChartTapped:(id)sender {

GrowthChartConfigOneViewController *panelViewController = [[GrowthChartConfigOneViewController alloc]init];

UIPopoverController *popover = [[UIPopoverController alloc]initWithContentViewController:panelViewController];
popover.delegate = self;

// Store the popover in a custom property for later use.
self.popover = popover;

[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
}

However, I did not find a way to set the size of the popover.

Question: Where and how should I set the size of the popover and its view controller? Can I set the size directly in XCode to have the view correctly sized in storyboard?


Solution

  • Just give popovercontentsize and make sure that view should fit in popover size as defined below:

        popover = [[UIPopoverController alloc] initWithContentViewController: panelViewController];
        popover.popoverContentSize = CGSizeMake(550, 700);