Skip to content

Instantly share code, notes, and snippets.

@cgoldsby
Last active September 3, 2017 16:13
Show Gist options
  • Save cgoldsby/1b208f37fb9d29533ee60a8bcb371bad to your computer and use it in GitHub Desktop.
Save cgoldsby/1b208f37fb9d29533ee60a8bcb371bad to your computer and use it in GitHub Desktop.
Display a popover with the same style as an iPad
final class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
...
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let popoverViewController = segue.destination
// Override the presentation style on the iPhone so that the popover does not appear in fullscreen
popoverViewController.popoverPresentationController?.delegate = self
// Depending on the viewable screen space present the popover either above or to the right of the label
popoverViewController.popoverPresentationController?.permittedArrowDirections = [.down, .left]
// Define the size of the popover
popoverViewController.preferredContentSize = CGSize(width: 100, height: 100)
// Present the popover from the label instead of the CTA button
popoverViewController.popoverPresentationController?.sourceRect = label.frame
popoverViewController.popoverPresentationController?.sourceView = label
}
// MARK: - UIPopoverPresentationControllerDelegate
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment