iOS- Swift:如何使用iOS8中的UIAlertController
1.前言
2.如何使用UIAlertController
2.2.第一种创建方式——默认提示框
最原始的init一般不用这种,默认是上拉菜单样式
import UIKit class ViewController: UIViewController { override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
// 单击屏幕触发 //方式一
var alertVC = UIAlertController()
alertVC.title = "Title"
alertVC.message = "Hello,My name Saup" //因为UIAlertController是控制器,所以我们现在得改用控制器弹出
self.presentViewController(alertVC, animated: true, completion: nil) }
效果图1:
2.2.第二种创建方式——自定义提示框
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
// 单击屏幕触发 //方式二 //创建控制器
var alertVC = UIAlertController(title: "Title", message: "Please choose!", preferredStyle: UIAlertControllerStyle.ActionSheet)
//创建按钮
var acSure = UIAlertAction(title: "Sure", style: UIAlertActionStyle.Default) { (UIAlertAction) -> Void in
print("click Sure")
} var acCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in
print("click Cancel")
} // var acDestuctive = UIAlertAction(title: "Destuctive", style: //UIAlertActionStyle.Destuctive) { (UIAlertAction) -> Void in
// print("click Destuctive")
// } alertVC.addAction(acSure)
alertVC.addAction(acCancel)
// alertVC.addAction(acDestuctive) //因为UIAlertController是控制器,所以我们现在得改用控制器弹出
self.presentViewController(alertVC, animated: true, completion: nil) }
效果图2:
2.3.第三种创建方式——文本对话框
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
// 单击屏幕触发 //方式三 //创建控制器
var alertVC = UIAlertController(title: "TextFiled", message: "Please input!", preferredStyle: UIAlertControllerStyle.Alert) alertVC.addTextFieldWithConfigurationHandler { (tField:UITextField!) -> Void in tField.placeholder = "Account" } alertVC.addTextFieldWithConfigurationHandler {(textField:UITextField!) -> Void in
textField.placeholder = "Password"
textField.secureTextEntry = true;
} var acOK = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (alertAction:UIAlertAction!) -> Void in }
var acCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (alertAction:UIAlertAction!) -> Void in
} acOK.enabled = false alertVC.addAction(acOK)
alertVC.addAction(acCancel) //因为UIAlertController是控制器,所以我们现在得改用控制器弹出
self.presentViewController(alertVC, animated: true, completion: nil)
}
效果图3:
作者: 清澈Saup
出处:http://www.cnblogs.com/qingche/
本文版权归作者和博客园共有,欢迎转载,但必须保留此段声明,且在文章页面明显位置给出原文连接。
iOS- Swift:如何使用iOS8中的UIAlertController的更多相关文章
- iOS 学习笔记 九 (2015.04.02)IOS8中使用UIAlertController创建警告窗口
1.IOS8中使用UIAlertController创建警告窗口 #pragma mark - 只能在IOS8中使用的,警告窗口- (void)showOkayCancelAlert{ NSSt ...
- iOS8中的UIAlertController
转: iOS8推出了几个新的“controller”,主要是把类似之前的UIAlertView变成了UIAlertController,这不经意的改变,貌似把我之前理解的“controlle ...
- iOS开发手记-iOS8中使用定位服务解决方案
问题描述: 在iOS8之前,app第一次开始定位服务时,系统会弹出一个提示框来让用户选择是否允许使用定位信息.但iOS8后,app将不会出现这个弹窗.第一次运行之后,在设置->隐私->定位 ...
- 在iOS 8中使用UIAlertController
iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...
- 【iOS】swift-ObjectC 在iOS 8中使用UIAlertController
iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...
- [iOS] 初探 iOS8 中的 Size Class
本文转载至 http://www.itnose.net/detail/6112176.html 以前和安卓的同学聊天的时候,谈到适配一直是一个非常开心的话题,看到他们被各种屏幕适配折磨的欲仙欲死 ...
- iOS开发--Swift 如何完成工程中Swift和OC的混编桥接(Cocoapods同样适用)
由于SDK现在大部分都是OC版本, 所以假如你是一名主要以Swift语言进行开发的开发者, 就要面临如何让OC和Swift兼容在一个工程中, 如果你没有进行过这样的操作, 会感觉异常的茫然, 不用担心 ...
- iOS8中的动态文本
原文链接 : Swift Programming 101: Mastering Dynamic Type in iOS 8 原文作者 : Kevin McNeish Apple声称鼓励第三方App能够 ...
- [Swift]UIKit学习之警告框:UIAlertController和UIAlertView
Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) T ...
随机推荐
- Delphi 调试连接 任意Android手机/平板/盒子
Delphi有时候无法连接调试一些手机,解决方案: 1.安装Google USB Driver 2.通过设备管理器查看手机或平板USB的VID,PID 3.修改你的电脑上的android_winusb ...
- Delphi Firemonkey在主线程 异步调用函数(延迟调用)
先看下面的FMX.Layouts.pas中一段代码 procedure TCustomScrollBox.MouseDown(Button: TMouseButton; Shift: TShiftSt ...
- centos6.9下安装python3.7
说明 以下所有操作都基于centos6.9 python3.7依赖openssl1.0.2,首先更新系统自带的openssl 建议 升级系统到centos7(系统openssl已升级到1.0.2) 升 ...
- Spring框架中用到的设计模式(转)
主要参考这篇文章 http://blog.didispace.com/spring-design-partern/
- 树莓派 raspberry系统 VNC View 连接 Cannot currently show the desktop 错误解决
https://www.raspberrypi.org/forums/viewtopic.php?t=216737 我是因为空间不够
- C语言中while语句里使用scanf的技巧
今天友人和我讨论了一段代码,是HDU的OJ上一道题目的解,代码如下 #include<stdio.h> { int a,b; while(~scanf("%d%d",& ...
- 20155301 《Java程序设计》实验二实验报告
20155301 <Java程序设计>实验二实验报告 一.单元测试和TDD 用程序解决问题时,要学会写以下三种代码: 伪代码 产品代码 测试代码 正确的顺序应为:伪代码(思路)→ 测试代码 ...
- 北京Uber优步司机奖励政策(4月13日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- day1 HTML - <head>
1.html是什么? 超文本标记语言(Hypertext Markup Language,HTML) <!DOCTYPE html> <html lang="en" ...
- Mac下 Windows 7 虚拟机成功搭建SVN服务器后如何与Xcode建立联系,并上传原始工程的详细步骤
内容中包含 base64string 图片造成字符过多,拒绝显示