Swift - 告警框(UIAlertView)的用法
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
|
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 UIKitclass 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)的用法的更多相关文章
- Swift - 告警提示框(UIAlertController)的用法
自iOS8起,苹果就建议告警框使用UIAlertController来代替UIAlertView.下面总结了一些常见的用法: 1,简单的应用(同时按钮响应Handler使用闭包函数) 1 2 3 ...
- swift - UIAlertView 的用法
1,创建一个alertview,并带有“确定”和“取消”两个按钮 (注:在这里使用alertview,会报警告,那是因为从ios 8 以后,建议使用UIAlertviewController) //警 ...
- selenium测试(Java)--告警框处理(十四)
下面代码中介绍了告警框的处理方法 package com.test.alerthandle; import org.openqa.selenium.By; import org.openqa.sele ...
- Ant Design Pro中Transfer穿梭框的实际用法(与后端交互)
Ant Design Pro中Transfer穿梭框的实际用法(与后端交互) 该控件的属性以及属性的作用在ADP的官方文档中都有介绍,但没有讲如何与后端交互,本文旨在讲解该控件与后端的交互. Ant ...
- Bootstrap告警框(alert)实现弹出效果和短暂消失后上浮消失
最近用到bootstrap的告警框时发现只有html的说明,就自己写了一个弹出告警框和弹出短暂显示后上浮消失的告警框. 直接上JS代码了,可以copy过去直接用(使用bootstrap的UI框架的情况 ...
- 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 ...
- [ios][swift]文本框UITextField用法
参考:http://www.hangge.com/blog/cache/detail_530.html
- IOS 警告框 (UIAlertView)的使用方法
1.普通警告框 IOS的SDK中提供了一个方便的类库UIAlertView,配合着不同参数来使用此类可以做出大多数的警告框,如下代码是IOS最简单的警告框. UIAlertView *alert = ...
- Swift - 故事板storyboard的用法
故事板(UIStoryboard)可以很方便的进行界面的设计,下面总结了常用的几个操作方法: 1,初始场景 选中View Controller,在属性面板里勾选Is Initial View Cont ...
随机推荐
- 解决screen Cannot open your terminal '/dev/pts/1'问题
转载于:http://urchin.blog.51cto.com/4356076/1153322 问题描述: userA首先登录系统,使用screen开启了一个session,然后detach这个窗口 ...
- svn: keywords
在文件头里面加入下面的关键字: $Date$ $ID$ $Revision$ $Author$ 代码在svn提交时,先选中这几个关键字再提交. Date可能出现中文乱码: 在Control Panel ...
- GridView点击空白地方事件扩展
我们通常在ListView或者GridView响应点击Item事件,但很多时候我们同样也 希望监听到点击空白区域的事件来做更多的处理.本文以GridView为例给出一个实现 的方法,扩展GridVie ...
- 嵌入jetty到Java代码
在做Demo实例时,使用的jetty版本号为8.x. 为了避免麻烦,将全部的包都导入到MyEclipse的lib文件夹下. 实例1:自己定义handler的服务器 package com.jetty. ...
- Java8 Lamdba表达式 001
在一个已经存在的编程语言里非常少有对现有的生态系统起重大影响的新特性.Lambda表达式对于Java语言就是这样的意义的存在.简单来说,Lambda表达式提供了便利的方式去创建一个匿名的功能.提供了一 ...
- mysql的用户管理(二)
与权限相关的表由于经常需要用到,所以mysql直接将这些表在mysql启动时写到了内存中,避免每次验证权限时再从磁盘写数据. 当以下条件发生时发refresh权限表信息到内存: 1.对帐户的更改时,如 ...
- Delphi体系内部的4种消息传递办法(Send,Post,Perform,Dispatch)
一.什么是消息? 消息是windows对应用程序发送的有关‘发生了某种事件’的通知.例如点击鼠标,调整窗口大小或键盘上按下一个键,都会引起windows发送一条消息到应用程序中去,去通知应用程序发生了 ...
- The parent project must have a packaging type of POM
在Eclipse中使用Maven添加模块时报错:The parent project must have a packaging type of POM 解决办法: 是将pom.xml 中的 < ...
- boost操作xml 5分钟官方教程
Five Minute Tutorial This tutorial uses XML. Note that the library is not specifically bound to XML, ...
- 生成awr报告
主要参考文献: http://343766868.blog.163.com/blog/static/48314056201110124513396/ 概况 Oracle内部以一定的频率把系统关键的统计 ...