Burak Üstün

Popover iPhone & iPad (Swift 3.1)

Round Button
    @IBAction func button_Click(_ sender: Any) {
        let popController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popOverViewContollerID")
        // set the presentation style
        popController.modalPresentationStyle                                    = UIModalPresentationStyle.popover
        // set up the popover presentation controller
        popController.popoverPresentationController?.permittedArrowDirections   = UIPopoverArrowDirection.up
        popController.popoverPresentationController?.delegate                   = self
        //---For Bar Button Items-------
        popController.popoverPresentationController?.barButtonItem              = self.barbutton
        //------------------------------
        //---For Buttons----------------
        popController.popoverPresentationController?.sourceView                 = button
        popController.popoverPresentationController?.sourceRect                 = button.bounds
        //------------------------------
        popController.preferredContentSize                                      = CGSize(width:  2 * self.view.frame.width/3,
                                                                                         height: 3 * self.view.frame.height/4)
        popController.popoverPresentationController?.backgroundColor            = UIColor.white
        // present the popover
        self.present(popController, animated: true, completion: nil)
    } 

Delegate Method:

extension ScheduleViewController: UIPopoverPresentationControllerDelegate{
    func adaptivePresentationStyle(for controller:UIPresentationController) -> UIModalPresentationStyle {
        return .none
    }
}
April 15, 2017