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?
You can also set it within the popover class itself. This way if you allow the popover to be called from multiple places, you can just set the size once.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.view.backgroundColor = [UIColor redColor];
self.contentSizeForViewInPopover = CGSizeMake(320.0, 216.0);
}
return self;
}
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With