How to change the size of a popover How to change the size of a popover ios ios

How to change the size of a 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 inspectorViewController>Check Use Preferred Explicit size and input values.enter image description here

Using Auto Layout

It may be worth mentioning that you can use layout constraints instead of setting preferredContentSize to specific values. To do so,

  1. Add this to your view controller:

    override func viewWillAppear(_ animated: Bool) {    super.viewWillAppear(animated)    self.preferredContentSize = self.view.systemLayoutSizeFitting(        UIView.layoutFittingCompressedSize    )}
  2. Ensure that you have constraints from your popover view to the controller's root view. These can be low priority, space >= 0 constraints.