How do you programmatically customize and present popover on iPhone in iOS 8+

As you can imagine, the UIViewController is in a popover on iPhone (all sizes and orientations), in iOS 8, using only Objective-C code, no posters or other Interface Builder artifacts.

+5
source share
1 answer

In iOS 8, you can configure any view controller that will be displayed as a popcorn, for example:

UIViewController* controller = ...; // your initialization goes here // set modal presentation style to popover on your view controller // must be done before you reference controller.popoverPresentationController controller.modalPresentationStyle = UIModalPresentationPopover; controller.preferredContentSize = CGSizeMake(150, 300); // configure popover style & delegate UIPopoverPresentationController *popover = controller.popoverPresentationController; popover.delegate = controller; popover.sourceView = sourceView; popover.sourceRect = CGRectMake(150,300,1,1); popover.permittedArrowDirections = UIPopoverArrowDirectionAny; // display the controller in the usual way [self presentViewController:controller animated:YES completion:nil]; 

To make it appear as a popover on the iPhone, add it to the UIPopoverPresentationControllerDelegate delegate from popover (which you installed above):

 - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { return UIModalPresentationNone; } 
+14
source

All Articles