How can i implement this popup menu in iphone app like a popover in ipad?
EDIT: This is the best at moment: https://github.com/runway20/PopoverView
Add a new file to the project, Select File -> New ->File and then select iOS -> Source -> Cocoa Touch Class. Name it PopoverViewController and make it a subclass of UIViewController. Go back to Main. storyboard and select the added View Controller.
A popover is a transient view that appears above other content onscreen when people click or tap a control or interactive area.
Beginning with iOS 8, you can use UIPopoverPresentationController
for iPhones in addition to iPads.
UIBarButtonItem
to your main View Controller. UILabel
. If you want a whole menu, then just add a table view or list of buttons.show
, choose Present as Popover
.popoverSegue
(or whatever string you called it in the code).This is the code for the main view controller that has the bar button item in it.
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate { override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "popoverSegue" { let popoverViewController = segue.destinationViewController popoverViewController.modalPresentationStyle = UIModalPresentationStyle.Popover popoverViewController.popoverPresentationController!.delegate = self } } // MARK: - UIPopoverPresentationControllerDelegate method func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { // Force popover style return UIModalPresentationStyle.None } }
If you want to set the popover to appear somewhere besides a bar button item (on a UIButton
for example) then you need to set the sourceView
and sourceRect
. See this answer for details.
The above example comes mostly from the first link.
Have a look at the iPhone UIPopoverController implementation: WEPopover
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With