Skip to content

Instantly share code, notes, and snippets.

@fcaldarelli
Last active March 28, 2020 02:52
Show Gist options
  • Save fcaldarelli/5bd88d2bf833b213d824506eb1758056 to your computer and use it in GitHub Desktop.
Save fcaldarelli/5bd88d2bf833b213d824506eb1758056 to your computer and use it in GitHub Desktop.
UIAlertController centered in iPad
UIPopoverPresentationController *popPresenter = ac.popoverPresentationController;
popPresenter.sourceView = self.view;
popPresenter.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0);
popPresenter.permittedArrowDirections = 0;
let popPresenter = ac.popoverPresentationController
popPresenter?.sourceView = view
popPresenter?.sourceRect = CGRect(x: view.bounds.midX, y: view.bounds.midY, width: 0, height: 0)
popPresenter?.permittedArrowDirections = []
// Update 28/03/2020
if UIDevice.current.userInterfaceIdiom == .pad {
alertController.popoverPresentationController?.sourceView = sourceView
alertController.popoverPresentationController?.sourceRect = sourceView.bounds
alertController.popoverPresentationController?.permittedArrowDirections = [.down, .up]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment