Search code examples
iosresizeswiftuipickerviewuipopovercontroller

UIPopoverController don't make resize


I'm using UIPopoverController tho show a view, in that view I have a UIPickerView, when a use presentPopoverFromRect , the PopOverControll Shows in the x and y correct position but not resizes the control. This viewController is a separated .swift file.

var buttonCenter: CGPoint = BtCheque.center;            
var rect:CGRect = CGRectMake(buttonCenter.x, 1, 120, 90);                
_colorPickerPopover.presentPopoverFromRect(rect, inView: self.view , permittedArrowDirections: UIPopoverArrowDirection.Up, animated: true);

The UIPickerView has the correct size, but the popUp doesn't.

This is the result:

Image result


Solution

  • I believe you misunderstood how presentPopoverFromRect works, it specify rectangle from which your popover will show itself, this is not rectangle of your popover.

    For example if you have a button with frame (10, 10, 100, 30) and after you press this button you want to show popover, this is the recommended frame you should pass to presentPopoverFromRect, not popover frame.

    To specify size of your popover use popoverContentSize property for your _colorPickerPopover.

    You can also set preferredContentSize in, for example, viewDidLoad method in your popover subclass.