博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swift - 警告提示框(UIAlertController)的用法
阅读量:4310 次
发布时间:2019-06-06

本文共 2387 字,大约阅读时间需要 7 分钟。

这里写图片描述

import UIKitclass ViewController: UIViewController {    override func viewDidLoad() {        super.viewDidLoad()    }    override func touchesBegan(touches: Set
, withEvent event: UIEvent?) { // 创建 let alertController = UIAlertController(title: "提示", message: "你确定要离开?", preferredStyle:.Alert) // 设置2个UIAlertAction let cancelAction = UIAlertAction(title: "取消", style: .Cancel, handler: nil) let okAction = UIAlertAction(title: "好的", style: .Default) { (UIAlertAction) in print("点击了好的") } // 添加 alertController.addAction(cancelAction) alertController.addAction(okAction) // 弹出 self.presentViewController(alertController, animated: true, completion: nil) } }

这里写图片描述

// 除了弹出,还可以使用底部向上滑出的样式        // 注意:如果上拉菜单中有『取消』按钮的话,那么它永远都会出现在菜单的底部,不管添加的次序如何        // 创建        // preferredStyle 为 ActionSheet        let alertController = UIAlertController(title: "保存或删除数据", message: "删除数据将不可恢复", preferredStyle:.ActionSheet) // 设置2个UIAlertAction let cancelAction = UIAlertAction(title: "取消", style: .Cancel, handler: nil) let deleteAction = UIAlertAction(title: "删除", style: .Destructive, handler: nil) let saveAction = UIAlertAction(title: "保存", style: .Default, handler: nil) // 添加到UIAlertController alertController.addAction(cancelAction) alertController.addAction(saveAction) alertController.addAction(deleteAction) // 弹出 self.presentViewController(alertController, animated: true, completion: nil)

这里写图片描述

/*        添加任意数量的文本输入框(比如可以用来实现登录框)         */        let alertController = UIAlertController(title: "系统登录", message: "请输入用户名和密码", preferredStyle: UIAlertControllerStyle.Alert)        alertController.addTextFieldWithConfigurationHandler { (textField:UITextField) in textField.placeholder = "用户名" } alertController.addTextFieldWithConfigurationHandler { (textField:UITextField) in textField.placeholder = "密码" textField.secureTextEntry = true } let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil) let okAction = UIAlertAction(title: "好的", style: UIAlertActionStyle.Default) { (UIAlertAction) in let login = alertController.textFields![0] let pwd = alertController.textFields![1] print("用户名:\(login.text) 密码:\(pwd.text)") } alertController.addAction(cancelAction) alertController.addAction(okAction) // 弹出 self.presentViewController(alertController, animated: true, completion: nil)

转载于:https://www.cnblogs.com/Free-Thinker/p/6372952.html

你可能感兴趣的文章
spout详解
查看>>
一个md5加密的工具类,用的虚拟机的包,不需要额外导包
查看>>
centos7在VMware下配置网络连接
查看>>
希尔排序 堆排序 归并排序
查看>>
ckplayer插件播放视频
查看>>
寻找最好的笔记软件:三强篇(EverNote、Mybase、Surfulater) (v1.0)
查看>>
时间长了不用,什么都忘了
查看>>
Eclipse 配置Activiti插件
查看>>
正则符号
查看>>
mysql事件
查看>>
小米系统获取root权限的完整教程
查看>>
hdu1114Piggy-Bank(完全背包)
查看>>
迷宫城堡 HDU - 1269 (强连通分量)
查看>>
eigenface资料整合
查看>>
jquery tree的使用
查看>>
JS构造函数、原型对象、隐含参数this
查看>>
delegate 与 event 不得不说的关系~
查看>>
Bootstrap 基础讲解2
查看>>
获取ServletContext
查看>>
七周成为数据分析师07_统计学基础
查看>>