swift 学习之 UIAlertViewController
// PushViewController.swift
// tab
//
// Created by su on 15/12/7.
// Copyright © 2015年 tian. All rights reserved.
//
import UIKit
class PushViewController: UIViewController {
var alert1: UIAlertController!
var alert2: UIAlertController!
var actionSheet: UIAlertController!
override func viewDidLoad() {
super.viewDidLoad()
// label.frame = CGRect(x: 20, y: 100, width: Tools().SCREEN_WIDTH, height: 100)
// label.backgroundColor = Tools().RGB(r: 123, g: 234, b: 132)
// 定义一个按钮,显示最简单的 Alert
let button1 = UIButton(type: UIButtonType.System)
button1.frame = CGRectMake(self.view.frame.width/2 - 200, 50, 400, 50)
button1.setTitle("最简单的 Alert", forState: UIControlState.Normal)
button1.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
button1.tag = 1
self.view.addSubview(button1)
// 定义一个按钮,显示带文本框的 Alert
let button2 = UIButton(type: UIButtonType.System)
button2.frame = CGRectMake(self.view.frame.width/2 - 200, 150, 400, 50)
button2.setTitle("带文本框的 Alert", forState: UIControlState.Normal)
button2.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
button2.tag = 2
self.view.addSubview(button2)
// 定义一个按钮,显示上拉菜单
let button3 = UIButton(type: UIButtonType.System)
button3.frame = CGRectMake(self.view.frame.width/2 - 200, 250, 400, 50)
button3.setTitle("上拉菜单", forState: UIControlState.Normal)
button3.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
button3.tag = 3
self.view.addSubview(button3)
// 定义 cancel、ok、save、delete、reset 的 UIAlertAction
let cancelAction = UIAlertAction(title: "cancel", style: UIAlertActionStyle.Cancel, handler: nil)
let okAction = UIAlertAction(title: "ok", style: UIAlertActionStyle.Default){
(action: UIAlertAction!) -> Void in
print("you choose ok")
}
let saveAction = UIAlertAction(title: "save", style: UIAlertActionStyle.Default){
(action: UIAlertAction!) -> Void in
print("you choose save")
}
let deleteAction = UIAlertAction(title: "delete", style: UIAlertActionStyle.Destructive){
(action: UIAlertAction!) -> Void in
print("you choose delete")
}
let resetAction = UIAlertAction(title: "reset", style: UIAlertActionStyle.Destructive){
(action: UIAlertAction!) -> Void in
print("you choose reset")
}
// 1、初始化最简单的 Alert
alert1 = UIAlertController(title: "simple alert", message: "this is a simple alert", preferredStyle: UIAlertControllerStyle.Alert)
alert1.addAction(cancelAction)
alert1.addAction(resetAction)
alert1.addAction(okAction)
// 2、初始化带文本框的 Alert
alert2 = UIAlertController(title: "login alert", message: "please enter your name and password", preferredStyle: UIAlertControllerStyle.Alert)
alert2.addTextFieldWithConfigurationHandler {
(textField: UITextField!) -> Void in
textField.placeholder = "name"
}
alert2.addTextFieldWithConfigurationHandler {
(textField: UITextField!) -> Void in
textField.placeholder = "password"
textField.secureTextEntry = true
}
let loginAction = UIAlertAction(title: "login", style: UIAlertActionStyle.Default) {
(action: UIAlertAction!) -> Void in
let name = self.alert2.textFields!.first
let password = self.alert2.textFields!.last
print("name : \(name!.text) password : \(password!.text)")
}
alert2.addAction(loginAction)
// 3、初始化上拉菜单
actionSheet = UIAlertController(title: "simple action sheet", message: "action sheet message", preferredStyle: UIAlertControllerStyle.ActionSheet)
actionSheet.addAction(cancelAction)
actionSheet.addAction(deleteAction)
actionSheet.addAction(saveAction)
}
/// 按钮响应事件
func buttonAction(sender: UIButton) {
let num = sender.tag
switch num {
case 1:
self.presentViewController(alert1, animated: true, completion: nil)
case 2:
self.presentViewController(alert2, animated: true, completion: nil)
case 3:
self.presentViewController(actionSheet, animated: true, completion: nil)
default:
break
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
swift 学习之 UIAlertViewController的更多相关文章
- swift学习之-- UIAlertVIewController - uiactionsheet
// // ViewController.swift // actionsheet // // Created by su on 15/12/7. // Copyright © 2015年 t ...
- swift学习之-- UIAlertViewController -alert
// // ViewController.swift // alertView // // Created by su on 15/12/7. // Copyright © 2015年 tia ...
- 【swift学习笔记】二.页面转跳数据回传
上一篇我们介绍了页面转跳:[swift学习笔记]一.页面转跳的条件判断和传值 这一篇说一下如何把数据回传回父页面,如下图所示,这个例子很简单,只是把传过去的数据加上了"回传"两个字 ...
- 今天开始Swift学习
今天开始Swift学习 在此记录笔记 以备之后查阅! allenhuang
- iOS ---Swift学习与复习
swift中文网 http://www.swiftv.cn http://swifter.tips/ http://objccn.io/ http://www.swiftmi.com/code4swi ...
- 12套swift学习资源分享
虽然objective-c编程语言在过去很长一段时间都是iOS应用开发的基础语言,且很多iOS开发者对其也深爱有佳,但是随着swift编程语言的问世,迅速发展为开发者追捧的语言.且今年伴随着swift ...
- Swift学习之常用UI的使用
Swift学习之常用UI的使用 最近笔者在开始学习苹果最新的编程语言,因为笔者认为,苹果既然出了这门语言就绝对不会放弃,除非苹果倒闭了(当然这里知识一个玩笑). 所以在不久的将来,swift绝对是iO ...
- [转]swift 学习资源 大集合
今天看到了一个swift的学习网站,里面收集了很多学习资源 [转自http://blog.csdn.net/sqc3375177/article/details/29206779] Swift 介绍 ...
- swift 学习资源 大集合
今天看到一个swift学习网站,其中我们收集了大量的学习资源 Swift 介绍 Swift 介绍 来自 Apple 官方 Swift 简单介绍 (@peng_gong) 一篇不错的中文简单介绍 [译] ...
随机推荐
- 如何利用 AVDictionary 配置参数(转)
本文是我的 FFMPEG Tips 系列的第五篇文章,准备介绍下 ffmpeg 提供的一个非常好用的健值对工具:AVDictionary,特别是对于没有 map 容器的 c 代码,可以充分利用它来配置 ...
- linq to sql 怎么查询前 11 条数据
(from 新表 in db.books where 新表.bookid < 400 select 新表).Take(11); storeDB.Albums.OrderByDescending( ...
- 洛谷2473(SCOI2008)奖励关
题目:https://www.luogu.org/problemnew/show/P2473 因为可不可选此物与之前选过什么物品有关,所以状态可以记录成前面已经选过什么物品. 因为选不选此物与它带来的 ...
- iPhone应用提交流程:如何将App程序发布到App Store
http://www.techolics.com/apple/20120401_197.html 对于刚加入iOS应用开发行列的开发者来说,终于经过艰苦的Coding后完成了第一个应用后最重要的历史时 ...
- 修改numa和io调度优化mysql性能
一.NUMA设置单机单实例,建议关闭NUMA,关闭的方法有三种:1.硬件层,在BIOS中设置关闭:2.OS内核,启动时设置numa=off:3.可以用numactl命令将内存分配策略修改为interl ...
- NPOI-Excel系列-1000.创建一个标准的Excel文件
using NPOI.HSSF.UserModel; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.IO; name ...
- java.lang.NumberFormatException:For input string:"undefined"
在将字符串转换为数字时导致此错误,解决此问题的思路: 1.添加 try catch语句 2.判断字符串是否为数字,将介绍java中判断字符串是否为数字的方法的几种方法 发生错误的代码: java.la ...
- mac电脑 pip安装包后 撞到了系统python里面的解决方法
/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-pack ...
- 使用JS获取当前地理位置方法汇总(如用谷歌接口,会出再以上报错,必须申请密钥并设置接受服务器IP!!!)
RefererNotAllowedMapError 错误 加载 Google Maps JavaScript API 的当前 URL 尚未添加到允许的引用站点列表中.请在 Google API Con ...
- Oracle Database PSU/CPU
1. 什么是PSU/CPU?CPU: Critical Patch UpdateOracle对于其产品每个季度发行一次的安全补丁包,通常是为了修复产品中的安全隐患. PSU: Patch Set Up ...