当前位置: 博客首页 >> swift >> 阅读正文

swift3中提示框UIAlertController的使用

作者: 郑晓 分类: swift 发布于: 2017-03-21 18:30 浏览:5,594 没有评论


在xcode8 swift3中已经已经弃用了UIAlertView控件,统一使用UIAlertController代替,以下是UIAlertController的简单示例。

IBAction func myBtn(_ sender: Any) { let alertController = UIAlertController(title: "Demo", message: "确定还是取消", preferredStyle: .actionSheet) //定义取消按钮及事件 let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: { (UIAlertAction)->Void in print("你点击了取消按钮") //其它功能 }) //定义确定按钮及事件 let okAction = UIAlertAction(title: "确定", style: .default, handler:{ (UIAlertAction) -> Void in print("点击确定事件") //其它功能 }) //将定义的按钮添加到controller中 alertController.addAction(cancelAction) alertController.addAction(okAction)</p> <pre><code>self.present(alertController, animated: true, completion: nil)

} 其中preferredStyle可以是.alert 会在屏幕中心弹出,如果是.actionSheet 则是从底部弹出。 handler事件如果不需要可以设置为nil。

       

本文采用知识共享署名-非商业性使用 3.0 中国大陆许可协议进行许可,转载时请注明出处及相应链接。

本文永久链接: https://www.zh30.com/swift3-uialertcontroller.html

发表评论

change vcode