- 底部弹出菜单 actionSheet 样式
//底部弹窗框
let bomAlert = UIAlertController(title: "我是标题", message: "我是描述", preferredStyle: .actionSheet)
let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil);
let delAction = UIAlertAction(title: "删除", style: .destructive, handler: nil);
let saveAction = UIAlertAction(title: "保存", style: .default, handler: {(UIAlertAction) -> Void in
print("do save");
})
bomAlert.addAction(cancelAction)
bomAlert.addAction(delAction)
bomAlert.addAction(saveAction)
self.present(bomAlert, animated: true, completion: nil)
其中如果是ipad 弹出底部菜单可能会报错
需要做如下修改
修改前
@IBAction func alert(sender: UIButton) {
let alertController = UIAlertController(title: "My first app", message: "Hello World", preferredStyle: .ActionSheet)
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
修改后
@IBAction func alert(sender: UIButton) {
let alertController = UIAlertController(title: "My first app", message: "Hello World", preferredStyle: .ActionSheet)
//ipad使用,不加ipad上会崩溃
if let popoverController = alertController.popoverPresentationController {
popoverController.sourceView = sender
popoverController.sourceRect = sender.bounds
}
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
参考: http://blog.csdn.net/it_liuwei/article/details/49102227
显示结果:底部弹出窗口就会在 触发 弹出窗口的 按钮的 旁边显示
- Alert 弹出样式
let bomAlert = UIAlertController(title: "我是标题", message: "我是描述", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil);
let delAction = UIAlertAction(title: "删除", style: .destructive, handler: nil);
bomAlert.addAction(cancelAction)
bomAlert.addAction(delAction)
self.present(bomAlert, animated: true, completion: nil)