Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 803
AlexR Avatar asked Nov 23 '25 02:11

AlexR


2 Answers

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;
}
like image 199
DenVog Avatar answered Nov 25 '25 14:11

DenVog


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);
like image 43
Bhupendra Avatar answered Nov 25 '25 16:11

Bhupendra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!