Swift - 告警框(UIAlertView)的用法

Swift - 告警框(UIAlertView)的用法

1,下面代码创建并弹出一个告警框,并带有“取消”“确定”两个按钮
(注:自IOS8起,建议使用UIAlertController。点击查看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()
 
         let  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){
             print ( "点击了取消" )
         }
         else
         {
             print ( "点击了确认" )
         }
     }
}

2,告警框有下面4种样式
Default:默认样式
PlainTextInput:带输入框的告警框
SecureTextInput:带密码框的告警框
LoginAndPasswordInput:带输入框和密码框的告警框

下面是一个使用输入框和密码框的告警框样例:
原文:Swift - 告警框(UIAlertView)的用法

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){
             print ( "点击了取消" )
         }
         else
         {
             let  name = alertView.textFieldAtIndex(0)
             let  password = alertView.textFieldAtIndex(1)
             print ( "用户名是:\(name!.text) 密码是:\(password!.text)" )
         }
     }
 
     override  func  didReceiveMemoryWarning() {
         super .didReceiveMemoryWarning()
     }
}

原文出自: www.hangge.com   转载请保留原文链接: http://www.hangge.com/blog/cache/detail_537.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值