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
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.