Last active
September 3, 2017 16:13
-
-
Save cgoldsby/1b208f37fb9d29533ee60a8bcb371bad to your computer and use it in GitHub Desktop.
Display a popover with the same style as an iPad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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