RubyMotion Cookbook 笔记-第二章第一节显示弹出对话框

RubyMotion Cookbook笔记-第二章第一节显示弹出对话框

实验目的

制作一个弹出警告对话框,可输入账号与密码


 

代码部分

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    #初始化一个UIAlertView实例
    alert = UIAlertView.alloc.initWithTitle "Hello World",
                                             message: "It's a trap!",
                                             delegate: self,
                                             cancelButtonTitle: "Cancel",
                                             otherButtonTitles: "Ok",nil
    #设置外观样式,这里使用的是登陆名和密码
    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput
    
    #设置文本输入框的键盘布局
    text = alert.textFieldAtIndex 0
    text.keyboardType = UIKeyboardTypeNamePhonePad
    alert.show                                    
    true
  end
end

  

扩展部分

关于UIAlertView的初始化参数中最后一项 otherButtonTitles,是一个字符串的序列,必须以一个nil变量结尾。序列中的每个字符串都被初始化为一个对应标题值的按钮。

如下代码则会额外增加一个按钮

 

    alert = UIAlertView.alloc.initWithTitle "Hello World",
                                             message: "It's a trap!",
                                             delegate: self,
                                             cancelButtonTitle: "Cancel",
                                             otherButtonTitles: "Ok","Third Button",nil
 


 

 

关于UIAlertViewStyle的枚举值常用的有以下几种:

 

  • UIAlertViewStyleDefault = 0,            //缺省样式
  • UIAlertViewStyleSecureTextInput,         //密文输入框
  • UIAlertViewStylePlainTextInput,          //明文输入框
  • UIAlertViewStyleLoginAndPasswordInput         //上方明文下方密文输入框

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值