Reputation: 317
I Have a piece of code which is as follows: self.popOverController.popoverContentSize = CGSizeMake(248.0, 216.0);
This works fine in iOS 7 and below. However, it doesn't respond to CGSizeMake in iOS 8. No matter what the value is specified with in CGSizeMake(), it takes the same default size.
Please reply with an alternative code.
Upvotes: 8
Views: 2600
Reputation: 501
Take two steps to solve this
Step One:
As an immediate fix, you can set preferredContentSize
property of UIViewController
[popoverViewController setPreferredContentSize:CGSizeMake(248.0,216.0)];
before initalizing UIPopoverController
UIPopoverController *popoverController = [[UIPopoverController alloc]initWithContentViewController:popoverViewController];
Step Two:
In iOS8, UIPopoverPresentationController
is getting introduced as a replacement of UIPopoverController
if ([popoverViewController respondsToSelector:@selector(popoverPresentationController)]) { popoverViewController.modalPresentationStyle = UIModalPresentationPopover; [popoverViewController setPreferredContentSize:CGSizeMake(248.0,216.0)]; UIPopoverPresentationController *popoverPresentation = popoverViewController.popoverPresentationController; [popoverPresentation setSourceView:_sourceView]; [popoverPresentation setSourceRect:_sourceRect]; [popoverPresentation setPermittedArrowDirections:UIPopoverArrowDirectionUp]; [self presentViewController:popoverViewController animated:YES completion:nil]; } else { //existing code... }
As of now, pre-release documentation is available for further reference.
Upvotes: 9