iOS Present Popover from bar button item bottom

lukas picture lukas · Jun 17, 2014 · Viewed 10.7k times · Source

I have an UIPopoverController that presents an UIViewController using this method:

[self.popover presentPopoverFromBarButtonItem:self.infoBarButtonItem 
                     permittedArrowDirections:UIPopoverArrowDirectionUp
                                     animated:YES];

self.popover is my UIPopoverController.

The code works well, but the Popover arrow is in the middle of the BarButtonItem how do I display the Popover with its arrow "under" the button?

This is what it currently looks like:
altText

Answer

A.Gao picture A.Gao · Nov 16, 2015

In iOS 9 you can try this code:

let alert = UIAlertController(title: "title", message: "message", preferredStyle: UIAlertControllerStyle.ActionSheet)
alert.modalPresentationStyle = UIModalPresentationStyle.Popover
alert.popoverPresentationController?.barButtonItem = sender
presentViewController(alert, animated: true, completion: nil)