`
akiraray
  • 浏览: 87728 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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         //上方明文下方密文输入框

 

 

  • 大小: 54.3 KB
  • 大小: 42.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics