//
//  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的更多相关文章

  1. swift学习之-- UIAlertVIewController - uiactionsheet

    // //  ViewController.swift //  actionsheet // //  Created by su on 15/12/7. //  Copyright © 2015年 t ...

  2. swift学习之-- UIAlertViewController -alert

    // //  ViewController.swift //  alertView // //  Created by su on 15/12/7. //  Copyright © 2015年 tia ...

  3. 【swift学习笔记】二.页面转跳数据回传

    上一篇我们介绍了页面转跳:[swift学习笔记]一.页面转跳的条件判断和传值 这一篇说一下如何把数据回传回父页面,如下图所示,这个例子很简单,只是把传过去的数据加上了"回传"两个字 ...

  4. 今天开始Swift学习

    今天开始Swift学习  在此记录笔记  以备之后查阅! allenhuang

  5. iOS ---Swift学习与复习

    swift中文网 http://www.swiftv.cn http://swifter.tips/ http://objccn.io/ http://www.swiftmi.com/code4swi ...

  6. 12套swift学习资源分享

    虽然objective-c编程语言在过去很长一段时间都是iOS应用开发的基础语言,且很多iOS开发者对其也深爱有佳,但是随着swift编程语言的问世,迅速发展为开发者追捧的语言.且今年伴随着swift ...

  7. Swift学习之常用UI的使用

    Swift学习之常用UI的使用 最近笔者在开始学习苹果最新的编程语言,因为笔者认为,苹果既然出了这门语言就绝对不会放弃,除非苹果倒闭了(当然这里知识一个玩笑). 所以在不久的将来,swift绝对是iO ...

  8. [转]swift 学习资源 大集合

    今天看到了一个swift的学习网站,里面收集了很多学习资源 [转自http://blog.csdn.net/sqc3375177/article/details/29206779] Swift 介绍 ...

  9. swift 学习资源 大集合

    今天看到一个swift学习网站,其中我们收集了大量的学习资源 Swift 介绍 Swift 介绍 来自 Apple 官方 Swift 简单介绍 (@peng_gong) 一篇不错的中文简单介绍 [译] ...

随机推荐

  1. hdu 4336 Card Collector——最值反演

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max :全部出现的期望就是最晚出现 ...

  2. bzoj2721樱花——质因数分解

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2721 要推式子! 发现x和y一定都比 n! 大.不妨设 x = n!+k: 则1/x + 1 ...

  3. 我的第一个php扩展

    一.进入php源码包,找到ext文件夹 cd /owndata/software/php-5.4.13/ext 文件夹下放的都是php的相关扩展模块 二.生成自己的扩展文件夹和相关文件 php支持开发 ...

  4. 【linux】centos6.5上bugzilla的搭建

    1.安装依赖包 CentOS 6.5默认安装了apche,perl ,需要安装httpd mod_ssl mysql-server mysql php-mysql gcc perl* mod_perl ...

  5. python调用R语言,关联规则可视化

    首先当然要配置r语言环境变量什么的 D:\R-3.5.1\bin\x64; D:\R-3.5.1\bin\x64\R.dll;D:\R-3.5.1;D:\ProgramData\Anaconda3\L ...

  6. 【POJ】3378 Crazy Thairs(树状数组+dp+高精)

    题目 传送门:QWQ 分析 题意:给个数列,求有多少五元上升组 考虑简化一下问题:如果题目求二元上升组怎么做. 仿照一下逆序对,用树状数组维护一下就ok了. 三元怎么做呢? 把二元的拓展一位就可以了, ...

  7. SmallLocks

    folly/SmallLocks.h This module is currently x64 only. This header defines two very small mutex types ...

  8. 使用GridFsTemplate在Mongo中存取文件

      Maven依赖(还有一些springboot需要的) <parent> <groupId>org.springframework.boot</groupId> ...

  9. C++中构造函数作用

    一. 构造函数是干什么的 class Counter { public: // 类Counter的构造函数 // 特点:以类名作为函数名,无返回类型 Counter() { m_value = ; } ...

  10. LUA表的引用理解

    --lua中引用类型都是分配在堆上的 --因此,我们在使用LUA的table时,可尽可能的使用表的引用,而不需要拷贝表里的元素 --比如,通过RPC协议传来一个表A,我们想要缓存这个表,只需要保存该表 ...