Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the size of a popover

Tags:

ios

swift

popover

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"

like image 988
icestorm0806 Avatar asked May 19 '16 22:05

icestorm0806


People also ask

How do you change the width of a popover in material UI?

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.

How do you move popovers?

At the moment, the only way to move the mouse to the popover is by follwing the small arrow underneath the popover.


2 Answers

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)          }     } 
like image 184
beyowulf Avatar answered Sep 22 '22 00:09

beyowulf


I fixed it via storyboard : Click on your controller Click on Attribute inspector ViewController> Check Use Preferred Explicit size and input values. enter image description here

like image 22
Zeeshan Avatar answered Sep 24 '22 00:09

Zeeshan