1.以下是CCEditBox的相关函数和类型说明:

/*

编辑框的一些函数

setText("字符串"); //设置文本

setFontColor(color); //设置文本颜色

setPlaceHolder("文本"); //设置预设文本

getPlaceHolder(对象); //获得预设文本

setMaxLength(对象); //设置最大长度

getMaxLength(对象); //获得最大长度

setInputMode(); //设置键盘模式

setInputFlag(); //设置文本类型

setReturnType(); //设置键盘return类型

1.setInputMode

这里cocos2dx给我们提供了很多键盘的模式,我们来一一了解下。

kEditBoxInputModeAny //文本键盘(含换行)

kEditBoxInputModeEmailAddr //邮件类键盘

kEditBoxInputModeNumeric //数字符号键盘

kEditBoxInputModePhoneNumber //电话号码键盘

kEditBoxInputModeUrl //URL键盘

kEditBoxInputModeDecimal //输入键盘(含小数点)

kEditBoxInputModeSingleLine //文本键盘(不含换行)

2.setInputFlag

这里cocos2dx给我们提供了5种文本类型。

kEditBoxInputFlagPassword //密码形式

kEditBoxInputFlagSensitive //敏感数据输入

kEditBoxInputFlagInitialCapsWord //每个单词首字符大写,并有提示

kEditBoxInputFlagInitialCapsSentence //第一句首字符大写,并有提示

kEditBoxInputFlagInitialCapsAllCharacters //自动大写

3.setReturnType

这里cocos2dx给我们提供了5种键盘返回类型。

kKeyboardReturnTypeDefault //默认类型

kKeyboardReturnTypeDone //Done字样

kKeyboardReturnTypeSend //Send字样

kKeyboardReturnTypeSearch //Search字样

kKeyboardReturnTypeGo //Go字样

*/

2.以下是我的登陆界面,作为测试使用!

bool HelloWorld::init(){

if ( !CCLayerColor::initWithColor(ccc4(255, 255, 2555, 255))){

return false;

}

CCLayerColor::initWithColor(ccc4(255, 0, 0, 255));

CCSize size=CCDirector::sharedDirector()->getWinSize();

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("market_sell.plist");

CCLabelTTF *l_username=CCLabelTTF::create("账号", "", 26);

l_username->setPosition(ccp(size.width* 0.5-200, 220));

addChild(l_username);

ed_username= createEditBox("sell_editboxBg.png", CCSizeMake(300,60), "", 20, ccc3(255, 0, 0), 5, "请输入帐号", kEditBoxInputModeSingleLine, kEditBoxInputFlagSensitive, kKeyboardReturnTypeDone);

ed_username->setText("");

ed_username->setPosition(ccp(size.width*0.5, 220));

addChild(ed_username);

ed_username->setDelegate(this);////设置代理

CCLabelTTF *l_password=CCLabelTTF::create("密码", "", 26);

l_password->setPosition(ccp(size.width* 0.5-200, 120));

addChild(l_password);

ed_password= createEditBox("sell_editboxBg.png", CCSizeMake(300,60), "", 20, ccc3(255, 0, 0), 12, "输入密码", kEditBoxInputModeSingleLine, kEditBoxInputFlagPassword, kKeyboardReturnTypeDone);

ed_password->setText("");

ed_password->setPosition(ccp(size.width* 0.5, 120));

addChild(ed_password);

ed_password->setDelegate(this);

this->setTouchEnabled(true);

return true;

}

//事件响应顺序如下:editBoxEditingDidBegin-> editBoxTextChanged-> editBoxEditingDidEnd-> editBoxReturn(注意:点击屏幕也会触发editBoxReturn)

void HelloWorld::editBoxEditingDidBegin(CCEditBox* editBox){

CCLog("**********Begin");

}

void HelloWorld::editBoxTextChanged(CCEditBox* editBox, const std::string& text){

CCLog("**********Changed");

}

void HelloWorld::editBoxEditingDidEnd(CCEditBox* editBox){

CCLog("**********ended");

}

void HelloWorld::editBoxReturn(CCEditBox* editBox){

CCLog("**********Return");

if (ed_username == editBox){

isNameNull=(strlen(ed_username->getText())==0);

if (isNameNull) {

CCMessageBox("Tip", "用户名不能为空");

}else{

ed_password->setPlaceHolder("点击输入");

ed_password->sendActionsForControlEvents(CCControlEventTouchUpInside);//需要再点击一次,才能输入

}

}else if (ed_password == editBox){

isPsdNull=(strlen(ed_password->getText())==0);

if (isPsdNull) {

CCMessageBox("Tip", "密码不能为空");

}

}

}

在代码里我使用了createEditBox这个全局方法。详细代码如下:

CCEditBox * createEditBox(const char *pFileName,CCSize size,const char* pFontName, int fontSize,const ccColor3B& color,int maxLength,const char* pPlaceHolderText,EditBoxInputMode inputMode,EditBoxInputFlag inputFlag,KeyboardReturnType returnType){

CCScale9Sprite *scale9Sprite=CCScale9Sprite::createWithSpriteFrameName(pFileName);

CCEditBox *editbox=CCEditBox::create(size, scale9Sprite);

editbox->setFontColor(color);

editbox->setFont(pFontName, fontSize);

editbox->setInputFlag(inputFlag);

editbox->setPlaceHolder(pPlaceHolderText);//当编辑框中没有任何字符的提示

editbox->setInputMode(inputMode);//设置输入模式

editbox->setReturnType(returnType);////设置键盘缩回按钮为return类型

editbox->setMaxLength(maxLength);//最大输入文本长度

return editbox;

}

CCEditBox用法的更多相关文章

  1. cocos2dx注册场景 使用CCEditBox实现输入框

    我们在开始玩一个游戏时,通常要做的第一件事就是注册账号,下面就让我们来制作一个简单的注册场景,我所使用的cocos2dx版本为2.2.2 在这个场景中最主要的元素就是输入框和按钮,我从网上找了一些素材 ...

  2. EditText 基本用法

    title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...

  3. jquery插件的用法之cookie 插件

    一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...

  4. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  5. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  6. python enumerate 用法

    A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...

  7. [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结

    本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...

  8. 【JavaScript】innerHTML、innerText和outerHTML的用法区别

    用法: <div id="test">   <span style="color:red">test1</span> tes ...

  9. chattr用法

    [root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...

随机推荐

  1. Matlab中Rand()函数用法

    一.理论准备 matlab函数randn:产生均值为0,方差 σ^2 = 1,标准差σ = 1的正态分布的随机数或矩阵的函数. 用法:Y = randn(n),返回一个n*n的随机项的矩阵.如果n不是 ...

  2. 【网络流24题】No.4 魔术球问题 (二分+最小路径覆盖)

    [题意] 假设有 n 根柱子, 现要按下述规则在这 n 根柱子中依次放入编号为 1, 2, 3, ¼的球.( 1)每次只能在某根柱子的最上面放球.( 2)在同一根柱子中,任何 2 个相邻球的编号之和为 ...

  3. 【UVA 11383】 Golden Tiger Claw (KM算法副产物)

    Omi, Raymondo, Clay and Kimiko are on new adventure- in search of new Shen Gong Wu. But EvilBoy Geni ...

  4. xbmc

    XBMC是一个优秀的自由和开源的(GPL)媒体中心软件.XBMC最初为Xbox而开发,可以运行在Linux.OSX.Windows.Android4.0系统.XBMC能够播放几乎所有流行的音频和视频格 ...

  5. android ListView异步加载图片(双缓存)

    首先声明,参考博客地址:http://www.iteye.com/topic/685986 对于ListView,相信很多人都很熟悉,因为确实太常见了,所以,做的用户体验更好,就成了我们的追求... ...

  6. MySQL源码 数据结构hash

    MySQL源码自定义了hash表,因为hash表具有O(1)的查询效率,所以,源码中大量使用了hash结构.下面就来看下hash表的定义: [源代码文件include/hash.h mysys/has ...

  7. BZOJ3156: 防御准备

    3156: 防御准备 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 442  Solved: 210[Submit][Status] Descript ...

  8. 新一批电子商务解决方案和企业管理应用加入 VM Depot 中国站点

     新一批电子商务解决方案和企业管理应用加入 VM Depot 中国站点. //电子商务平台助力您建设网店// 大约有 6 个最近更新的电子商务程序包已经登陆 VM Depot. 这不仅囊括了全球知 ...

  9. Android 颜色配置表-颜色类

    android开发中,常常会用到color.xml颜色配置,好的颜色配置可以让尼的应用让人看起来赏心悦目! 不罗嗦,上图先 该工程已经罗列了常用的颜色配置 附上工程链接:http://download ...

  10. 关于.NET三层 分类: C#

    三层体系结构的概念 用户界面表示层(USL) 业务逻辑层(BLL) 数据访问层(DAL) BLL将USL与DAL隔开了,并且加入了业务规则 各层的作用 1:数据数据访问层:主要是对原始数据(数据库或者 ...