I'm having trouble changing the size of my popover presentation. Here is what I have so far
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) // func for popover { if segue.identifier == "popoverView" { let vc = segue.destinationViewController let controller = vc.popoverPresentationController if controller != nil { controller?.delegate = self controller?.sourceView = self.view controller?.sourceRect = CGRect(x:CGRectGetMidX(self.view.bounds), y: CGRectGetMidY(self.view.bounds),width: 315,height: 230) controller?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0) } } }
So far all this does is center the popover and remove the arrow, which is good. but it doesn't resize the container. any help would be greatly appreciated. thank you.
when I use preferredContentSize I get the error "Cannot assign to property: 'preferredContentSize' is immutable"
The easiest way of doing that is to stretch the content inside the Popover, because it's width is calculated automatically. And that will stretch Popover itself to desired size.
At the moment, the only way to move the mouse to the popover is by follwing the small arrow underneath the popover.
Set the preferred content size on the view controller being presented not the popoverPresentationController
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) // func for popover { if segue.identifier == "popoverView" { let vc = segue.destinationViewController vc.preferredContentSize = CGSize(width: 200, height: 300) let controller = vc.popoverPresentationController controller?.delegate = self //you could set the following in your storyboard controller?.sourceView = self.view controller?.sourceRect = CGRect(x:CGRectGetMidX(self.view.bounds), y: CGRectGetMidY(self.view.bounds),width: 315,height: 230) controller?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0) } }
I fixed it via storyboard : Click on your controller Click on Attribute inspector ViewController> Check Use Preferred Explicit size and input values.
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