Ace Green
Ace Green

Reputation: 391

How to make UIPopoverController (Swift)?

Was looking for a swift based tutorial. My solution to the question is below

Hope it helps

Upvotes: 1

Views: 8186

Answers (2)

Ace Green
Ace Green

Reputation: 391

* Updated Answer *

class ViewController: UIViewController, UIPopoverControllerDelegate, UIPopoverPresentationControllerDelegate {

    @IBOutlet weak var RoutineLabel: UIButton!

    @IBAction func RoutineButton(sender: AnyObject) {

        switch SDiPhoneVersion.deviceVersion() {
        case DeviceVersion.iPad1, DeviceVersion.iPad2, DeviceVersion.iPadMini, DeviceVersion.iPad3, DeviceVersion.iPad4, DeviceVersion.iPadAir, DeviceVersion.iPadMiniRetina:

            var popoverViewController = self.storyboard?.instantiateViewControllerWithIdentifier("RoutinesTableViewController") as UITableViewController
            popoverViewController.modalPresentationStyle = .Popover
            popoverViewController.preferredContentSize   = CGSizeMake(300, 300)

            let popoverPresentationViewController = popoverViewController.popoverPresentationController

            popoverPresentationViewController?.permittedArrowDirections = UIPopoverArrowDirection.Up
            popoverPresentationViewController?.delegate = self
            popoverPresentationViewController?.sourceView = self.RoutineLabel
            popoverPresentationViewController?.sourceRect = CGRectMake(RoutineLabel.frame.width / 2, RoutineLabel.frame.height,0,0)

            presentViewController(popoverViewController, animated: true, completion: nil)


        default:

            println("iPhones")

        }

    }
}

Notes:

  • my PopPoverViewController is a UITableViewController
  • I use SDiPhoneVersion.deviceVersion to check for device version
  • I use a button to trigger it
  • I make the start of my pop up depend on RoutineLabel.frame

Upvotes: 5

GarlicFries
GarlicFries

Reputation: 8323

I won't pay to get past the paywall in the link you've given, but you're looking for UIPopoverController.

I also don't intend to write out a tutorial here--there are plenty of those available. A short and simple example of creating and using a UIPopoverController is given in this similar question: UIPopoverController, Xcode 6, IOS 8 using Swift

Upvotes: 2

Related Questions