FabrizioCaldarelli
5/2/2018 - 1:12 PM

UIAlertController centered in iPad

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]
}