Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PopOver from storyboard

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 736
    Comment on it

    Hi,

     

    Presenting popover from storyboard is easy and developer friendly. One can handle Popover from storyboard itself with a little code handling.
    Following are the steps to present Popover from storyboard.


    1- Draw an action segue from one controller to the destined controller(which you want to be present as Popover), give identifier name for that segue of your choice.
    2- Select “Present as Popover” in the action segue. Now you can see that a Popover segue has been created from source to destined controller.
    3- Now switch to Controller.swift (using swift classes for now) and override the function as

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    
            if segue.identifier == Your Identifier {
                if let controller = segue.destination as? DestinedViewController {
                    
                    controller.popoverPresentationController!.delegate = self
                    controller.modalPresentationStyle = .popover
                    controller.preferredContentSize = CGSize(width: 250, height: 200)
                    controller.popoverPresentationController?.permittedArrowDirections = .any
                }
            }
        }


    You can give size or your choice, we have taken 250, 200 just for example.

    4- Add one more method(delegate) to present the popOver accordingly, in case device type is iPhone.

    func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle{
            return .none
    }


    Now run the code and tap on the button from which you've created the Popover segue,  you’ll see that popover is presenting in the same size that was given while preparing segue.

     

     

    Thank you

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: