import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
super.viewDidLoad()
} override func touchesBegan(touches: Set<UITouch>, 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)

Swift - 警告提示框(UIAlertController)的用法的更多相关文章

  1. Swift - 告警提示框(UIAlertController)的用法

    自iOS8起,苹果就建议告警框使用UIAlertController来代替UIAlertView.下面总结了一些常见的用法: 1,简单的应用(同时按钮响应Handler使用闭包函数)    1 2 3 ...

  2. 选择提示框UIAlertController 和网络状态判断AFNetworking

    // 选择提示框 DownloadView *vc = [[DownloadView alloc] initWithFrame:CGRectMake(, , SCREEN_WIDTH, SCREEN_ ...

  3. iOS -iOS9中提示框(UIAlertController)的常见使用

    iOS 8 之前提示框主要使用 UIAlertView和UIActionSheet:iOS 9 将UIAlertView和UIActionSheet合二为一为:UIAlertController . ...

  4. js消息提示框插件-----toastr用法

     (本文系转载) 因为个人项目中有一个提交表单成功弹出框的需求,从网上找了一些资料,发现toastr这个插件的样式还是不错的.所以也给大家推荐下,但是网上的使用资料不是很详细,所以整理了一下,希望能给 ...

  5. Swift_IOS之提示框UIAlertController

    import UIKit class ViewController: UIViewController ,UIActionSheetDelegate{ @IBAction func btn1(_ se ...

  6. Android开发之AlertDialog警告提示框删除与取消 详解代码

    package cc.jiusansec.www; import android.app.Activity; import android.app.AlertDialog; import androi ...

  7. jquery仿alert提示框、confirm确认对话框、prompt带输入的提示框插件[附实例演示]

    jquery仿alert提示框.confirm确认对话框.prompt带输入的提示框插件实例演示 第一步:引入所需要的jquery插件文件: http://www.angelweb.cn/Inc/eg ...

  8. Java的awt包的使用实例和Java的一些提示框

    一.awt的一些组件 Label l1=new Label("姓名:"); //标签 Label l2=new Label("密码:"); TextField ...

  9. swift - UIAlertController 的用法

    ios 8 以后苹果官方建议使用UIAlertController这个类,所以专门去网上找资料,了解了下用法, 1.创建一个alertController let alertController = ...

随机推荐

  1. 关于指定dll搜索路径

    原文:关于指定dll搜索路径 问题现象 当部分DLL放在子文件夹下,需要指定DLL搜索路径,否则系统将找不到文件 产生原因 系统默认搜索只会在前程序目录并不包括子目录 解决方法 1,使用App.con ...

  2. 【习题 8-7 UVA - 11925】Generating Permutations

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 让你把排列1..n变换成对应的输入序列. 每次可以交换前两个数字,或者把第一个数字放到末尾去. 可以逆向考虑. 即把无序的序列变换成 ...

  3. C#打开SDE数据库的几种方式总结

    转自谢灿软件原文 C#打开SDE数据库的几种方式总结 1.通过指定连接属性参数打开数据库 /// <param name="server">数据库服务器名</pa ...

  4. HDOJ 5357 Easy Sequence DP

    a[i] 表示以i字符开头的合法序列有多少个 b[i] 表示以i字符结尾的合法序列有多少个 up表示上一层的'('的相应位置 mt[i] i匹配的相应位置 c[i] 包括i字符的合法序列个数  c[i ...

  5. Android 使用AIDL实现进程间的通信

    在Android中,如果我们需要在不同进程间实现通信,就需要用到AIDL技术去完成. AIDL(android Interface Definition Language)是一种接口定义语言,编译器通 ...

  6. codeforces 666E. Forensic Examination(广义后缀自动机,Parent树,线段树合并)

    传送门: 解题思路: 很坑的一道题,需要离线处理,假如只有一组询问,那么就可以直接将endpos集合直接累加输出就好了. 这里就要将询问挂在树节点上,在进行线段树合并时查询就好了. 代码超级容易写挂的 ...

  7. 重排序列 & 拓扑排序

    http://bookshadow.com/weblog/2016/10/30/leetcode-sequence-reconstruction/ 这道题目,检查重排的序列是否一致. 用了拓扑排序. ...

  8. [React] Render Elements Outside the Current React Tree using Portals in React 16

    By default the React Component Tree directly maps to the DOM Tree. In some cases when you have UI el ...

  9. HDU 4869 Turn the pokers(思维+组合公式+高速幂)

    pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...

  10. theme-windowAnimationStyle 动画四个方法的意义

    首先看代码 <style name="Animation.Activity"> <!--A打开B,B的出现动画--> <item name=" ...