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. C# MQTT 服务端客户端通讯

    关于MQTT 在这里我就不做过多的介绍了 , 超时空连接点我 MQTT示例 注: 该示例演示统一使用WPF, 简单MVVM模式演示, 复制代码需注意引用 NuGet包  GalaSoft MQTT服务 ...

  2. Python批量重命名指定目录下文件的两种方法

    #法一 import os path = "C://Python34//" for file in os.listdir(path): if os.path.isfile(os.p ...

  3. @JSONField 注解说明

    转自:https://blog.csdn.net/suyimin2010/article/details/80617538 导入@JSONField 注解: import com.alibaba.fa ...

  4. Red Hat Enterprise Linux Server 5.5新增功能简介

    一.概况 昨日对刚发布的redhat新产品RHEL5.5进行了小范围的测试,红帽企业版 Linux 5.5 发行本中的亮点包括针对 Intel Boxboro-EX 平台.AMD Magny-Cour ...

  5. C# 向DataTable中插入数据或伪造DataTable

    方法一: DataTable  tblDatas = new DataTable("Datas"); DataColumn dc = null; dc = tblDatas.Col ...

  6. JavaFx EventHandler

    import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHan ...

  7. 解决sublime text3配置Python3编译环境:运行代码时提示“NO Build System”

    只需要在路径中把单杠换成双杠,重启sublime即可.

  8. 9.Spring Boot实战之配置使用Logback进行日志记录

    转自:https://blog.csdn.net/meiliangdeng1990/article/details/54300227 Spring Boot实战之配置使用Logback进行日志记录 在 ...

  9. java hadoop file system API

    org.apache.hadoop.fs Class FileSystem java.lang.Object org.apache.hadoop.fs.FileSystem All Implement ...

  10. [Android 性能优化系列]内存之提升篇--应用应该怎样管理内存

    大家假设喜欢我的博客,请关注一下我的微博,请点击这里(http://weibo.com/kifile),谢谢 转载请标明出处(http://blog.csdn.net/kifile),再次感谢 原文地 ...