1,下面代码创建并弹出一个告警框,并带有“取消”“确定”两个按钮

(注:自IOS8起,建议使用UIAlertController)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class ViewController: UIViewController{
    override func viewDidLoad() {
        super.viewDidLoad()
 
        var alertView = UIAlertView()
        alertView.title = "系统提示"
        alertView.message = "您确定要离开hangge.com吗?"
        alertView.addButtonWithTitle("取消")
        alertView.addButtonWithTitle("确定")
        alertView.cancelButtonIndex=0
        alertView.delegate=self;
        alertView.show()
    }
 
    func alertView(alertView:UIAlertView, clickedButtonAtIndex buttonIndex: Int){
        if(buttonIndex==alertView.cancelButtonIndex){
            println("点击了取消")
        }
        else
        {
            println("点击了确认")
        }
    }
}

2,告警框有下面4种样式

Default:默认样式

PlainTextInput:带输入框的告警框

SecureTextInput:带密码框的告警框

LoginAndPasswordInput:带输入框和密码框的告警框

下面是一个使用输入框和密码框的告警框样例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import UIKit
 
class ViewController: UIViewController {
 
    var alertView = UIAlertView()
     
    override func viewDidLoad() {
        super.viewDidLoad()
         
        alertView.title = "系统登录"
        alertView.message = "请输入用户名和密码!"
        alertView.addButtonWithTitle("取消")
        alertView.addButtonWithTitle("确定")
        alertView.cancelButtonIndex=0
        alertView.delegate=self;
        alertView.alertViewStyle = UIAlertViewStyle.LoginAndPasswordInput
        alertView.show()
    }
     
    func alertView(alertView:UIAlertView, clickedButtonAtIndex buttonIndex: Int){
        if(buttonIndex==alertView.cancelButtonIndex){
            println("点击了取消")
        }
        else
        {
            let name = alertView.textFieldAtIndex(0)
            let password = alertView.textFieldAtIndex(1)
            println("用户名是:\(name!.text) 密码是:\(password!.text)")
        }
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

Swift - 告警框(UIAlertView)的用法的更多相关文章

  1. Swift - 告警提示框(UIAlertController)的用法

    自iOS8起,苹果就建议告警框使用UIAlertController来代替UIAlertView.下面总结了一些常见的用法: 1,简单的应用(同时按钮响应Handler使用闭包函数)    1 2 3 ...

  2. swift - UIAlertView 的用法

    1,创建一个alertview,并带有“确定”和“取消”两个按钮 (注:在这里使用alertview,会报警告,那是因为从ios 8 以后,建议使用UIAlertviewController) //警 ...

  3. selenium测试(Java)--告警框处理(十四)

    下面代码中介绍了告警框的处理方法 package com.test.alerthandle; import org.openqa.selenium.By; import org.openqa.sele ...

  4. Ant Design Pro中Transfer穿梭框的实际用法(与后端交互)

    Ant Design Pro中Transfer穿梭框的实际用法(与后端交互) 该控件的属性以及属性的作用在ADP的官方文档中都有介绍,但没有讲如何与后端交互,本文旨在讲解该控件与后端的交互. Ant ...

  5. Bootstrap告警框(alert)实现弹出效果和短暂消失后上浮消失

    最近用到bootstrap的告警框时发现只有html的说明,就自己写了一个弹出告警框和弹出短暂显示后上浮消失的告警框. 直接上JS代码了,可以copy过去直接用(使用bootstrap的UI框架的情况 ...

  6. Swift - 选择框(UIPickerView)的用法

    1,选择框可以让用户以滑动的方式选择值.示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...

  7. [ios][swift]文本框UITextField用法

    参考:http://www.hangge.com/blog/cache/detail_530.html

  8. IOS 警告框 (UIAlertView)的使用方法

    1.普通警告框 IOS的SDK中提供了一个方便的类库UIAlertView,配合着不同参数来使用此类可以做出大多数的警告框,如下代码是IOS最简单的警告框. UIAlertView *alert = ...

  9. Swift - 故事板storyboard的用法

    故事板(UIStoryboard)可以很方便的进行界面的设计,下面总结了常用的几个操作方法: 1,初始场景 选中View Controller,在属性面板里勾选Is Initial View Cont ...

随机推荐

  1. visual studio 2010配置驱动开发环境

    visual studio 2010 配置驱动开发环境 ** 工具/材料 VS2010.WDK开发包 **  配置过程 以下将讲述VS2010驱动开发环境的配置过程,至于必要软件的安装过程这里不再赘述 ...

  2. Python 第九篇:队列Queue、生产者消费者模型、(IO/异步IP/Select/Poll/Epool)、Mysql操作

    Mysql操作: grant select,insert,update,delete on *.* to root@"%" Identified by "123456&q ...

  3. ZOJ 3702 Fibonacci

    解题思路: 找规律,不难的,打表 坑的地方在于题目限定条件 and the seed value for G(1) is a random integer t, (t>=1) 虽然都用粗体表示出 ...

  4. Handler不同线程间的通信

    转http://www.iteye.com/problems/69457 Activity启动后点击一个界面按钮后会开启一个服务(暂定为padService),在padService中会启动一个线程( ...

  5. How to calculate the undo_retention time

    UNDO_RETENTION The undo_retention is a initialization parameter of the undo tablespace. The initiali ...

  6. Python:渗透测试开源项目

    Python:渗透测试开源项目[源码值得精读] sql注入工具:sqlmap DNS安全监测:DNSRecon 暴力破解测试工具:patator XSS漏洞利用工具:XSSer Web服务器压力测试工 ...

  7. IE6 png图片实现半透明的方法

    IE6中支持PNG半透明图片完美解决方法-divcss5亲測 从IE7及IE7以上版本号都支持PNG半透明格式图片,而只有IE6不支持png格式透明图片,而GIF半透明效果不及png半透明格式图片,由 ...

  8. FastDFS的学习与使用(大量帖子)

    http://www.oschina.net/p/fastdfs http://bbs.chinaunix.net/forum-240-1.html

  9. Ubuntu 挂载ISO文件的方法

    1.在终端中输入:sudo mkdir /media/iso 在/media下生成一个iso文件夹用来挂载iso文件2.然后输入:sudo mount -o loop /home/X/X/XXXX.i ...

  10. 基于visual Studio2013解决面试题之1101差值最小

     题目