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. flask_wtf flask 的 CSRF 源代码初研究

    因为要搞一个基于flask的前后端分离的个人网站,所以需要研究下flask的csrf防护原理. 用的扩展是flask_wtf,也算是比较官方的扩展库了. 先上相关源代码: def validate_c ...

  2. PA模块经常使用表

    SELECT * FROM pa_projects_all; --项目 SELECT * FROM pa_project_types; --项目类型 SELECT * FROM pa_project_ ...

  3. vue-cli(脚手架) 打包上线

    http://www.cnblogs.com/xueweijie/p/6971146.html

  4. 关于mybatis里面的Executor--转载

    原文地址:http://blog.csdn.net/w_intercool/article/details/7893344 使用mybatis查寻数据,跟踪其执行流程 最开始执行的语句 this.ge ...

  5. BZOJ1396: 识别子串(后缀自动机,线段树)

    Description Input 一行,一个由小写字母组成的字符串S,长度不超过10^5 Output L行,每行一个整数,第i行的数据表示关于S的第i个元素的最短识别子串有多长. Sample I ...

  6. 1.字符设备驱动------Linux中断处理体系结构

    一.中断处理体系结构的初始化 Linux内核将所有的中断统一编号,使用一个irq_desc结构数组来描述这些中断;每个数组项对应一个中断,也可能是一组中断,它们共用相同的中断号,里面记录了中断的名称. ...

  7. [Node.js] Serve Static Files with Express

    In this lesson we will find out how to serve static assets (images, css, stylesheets, etc.) with Exp ...

  8. 指示函数(indicator function) 的作用

    1. counter 指示函数常用于次数(满足某一断言或条件)的统计: 2. 二维的离散指示函数 ⇒ assignment solution xij∈{0,1},∑jxij=1 ∑jxij=1:行和为 ...

  9. Windows Forms 窗体篇

    1,显示窗体 非模式: Form form = new Form(); form.Show(); 模式: Form form = new Form(); form.Show(); 2,拥有者窗体与附属 ...

  10. 3. Vue-router 路由

    路由是根据不同的url地址展现不同的内容或页面. 前端路由就是把不同路由对应不同的内容或页面的任务交给前端来做(在单页面应用,大部分页面结构不变,只改变部分内容的使用),之前是通过服务器根据url的不 ...