UIAlertController

1 篇文章 / 0 new
author
UIAlertController
使用上需注意 iPhone 與 iPad 上的差異
@IBOutlet weak var moerItem: UIBarButtonItem!
 
let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)
 
alert.addAction(UIAlertAction(title: "Exit", style: .default) { _ in
    //self.dismiss(animated: false, completion: nil);
    print("exit");
    //self.dismiss(animated: true, completion:nil);
    exit(0);
});
//
if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone {
    // 如果是 iPhone
    self.present(alert, animated: true, completion: nil);
} else {
    // 如果是 iPad
    alert.popoverPresentationController?.barButtonItem = moerItem;//讓UI呈現在指定UIView 位置
    alert.popoverPresentationController?.sourceView = self.view;
    self.present(alert, animated: true, completion: nil);
}
Free Web Hosting