io8 How to set UIPopoverPresentationController size

dickfala picture dickfala · Feb 25, 2015 · Viewed 9.1k times · Source

I was set the UIPopoverPresentationController to show the UIViewController and that like UIAlertView show.

But when I created the customized UIViewController and use the UIPopoverPresentationController. There was show full screen.

I want to build the effect like http://cocoa.tumblr.com/post/92070238973/how-can-i-use-both-uipopoverpresentationcontroller

I had try to set preferredContentSize, but it still show full screen.

my code below:

 - (void)viewDidLoad {
     [super viewDidLoad];
     contentVC = [UIViewController new];
     contentVC.view.backgroundColor = [UIColor darkGrayColor];
     contentVC.preferredContentSize = CGSizeMake(200, 200);


     UIPopoverPresentationController *popPC =      contentVC.popoverPresentationController;
     popPC.delegate = self;
     popPC.sourceView = self.view;
     popPC.sourceRect = CGRectMake(0,0,0,0);
     popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
 }

 - (IBAction)btnAction:(id)sender {

 [self presentViewController:contentVC animated:NO completion:ni

 }

 -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
 {
     return UIModalPresentationOverCurrentContext;
 }

Have anyone know how to set the size in the uiviewcontroller and the UIPopoverPresentationController like the website effect?

I will set other component in the UIViewController(now just set backgroundcolor).

Thank you very much.

Answer

Hari Kunwar picture Hari Kunwar · Jul 18, 2016

In storyboard select the Navigation Controller and set Content Size values.

enter image description here

This can also be done in code by subclassing UINavigationController and setting preferredContentSize.

- (void)viewDidLoad {
   [super viewDidLoad];
   self.preferredContentSize = CGSizeMake(100, 100);
}