Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

io8 How to set UIPopoverPresentationController size

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.

like image 814
dickfala Avatar asked Feb 25 '15 00:02

dickfala


1 Answers

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);
}
like image 138
Hari Kunwar Avatar answered Sep 19 '22 02:09

Hari Kunwar