swift -> AlertController 弹出菜单视图

 

  • 底部弹出菜单 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)

 

 

 


 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值