CCEditBox 编辑框

原文: http://blog.csdn.net/cloud95/article/details/8773470

分类: cocos2d-x 2013-04-08 19:18 4356人阅读 评论(3) 收藏 举报

新建工程,名为testEdit.

修改HelloWorld.h

#ifndef __HELLOWORLD_SCENE_H__

#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

#include "cocos-ext.h"

usingnamespacecocos2d::extension;

class HelloWorld :
public
cocos2d::CCLayer,publicCCEditBoxDelegate

{

public:

// Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)

virtual bool init();

// there's no 'id' in cpp, so we recommend to return the class instance pointer

static cocos2d::CCScene* scene();

CREATE_FUNC(HelloWorld);

virtual void editBoxEditingDidBegin(CCEditBox *editBox);

virtual void editBoxEditingDidEnd(CCEditBox *editBox);

virtual void editBoxTextChanged(CCEditBox *editBox,const
std::string &text);

virtual void editBoxReturn(CCEditBox *editBox);

};

#endif // __HELLOWORLD_SCENE_H__

修改HelloWorld.cpp

#include "HelloWorldScene.h"

#include "SimpleAudioEngine.h"

usingnamespace
cocos2d;

usingnamespace
CocosDenshion;

#define testflag

CCScene* HelloWorld::scene()

{

// 'scene' is an autorelease object

CCScene *scene = CCScene::create();

// 'layer' is an autorelease object

HelloWorld *layer =
HelloWorld::create();

// add layer as a child to scene

scene->addChild(layer);

// return the scene

return scene;

}

// on "init" you need to initialize your instance

boolHelloWorld::init()

{

//////////////////////////////

// 1. super init first

if ( !CCLayer::init() )

{

return
false;

}

switch (testflag) {

:

{

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

CCScale9Sprite *sacel9SprY=
CCScale9Sprite::create("yellow_edit.png");

,
), sacel9SprY);

//设置编辑框内的文字

box->setText("");

//获取编辑框内的文字

CCLOG("Text:%s",box->getText());

//设置文本的颜色

box->,
, ));

//当编辑框中没有任何字符的提示

box->setPlaceHolder("请输入帐号");

CCLOG("PlaceHolder:%s",box->getPlaceHolder());

//最大输入文本长度

box->);

CCLOG("Length:%i",box->getMaxLength());

//设置输入模式

box->setInputMode(kEditBoxInputModeAny);

/**

//      kEditBoxInputModeAny:        
开启任何文本的输入键盘,包括换行

//      kEditBoxInputModeEmailAddr:  
开启 邮件地址
输入类型键盘

//      kEditBoxInputModeNumeric:    
开启 数字符号
输入类型键盘

//      kEditBoxInputModePhoneNumber:
开启 电话号码
输入类型键盘

//      kEditBoxInputModeUrl:        
开启 URL 输入类型键盘

//      kEditBoxInputModeDecimal:    
开启 数字
输入类型键盘,允许小数点

//      kEditBoxInputModeSingleLine: 
开启任何文本的输入键盘,不包括换行

//

*/

//设置输入类型

box->setInputFlag(kEditBoxInputFlagSensitive);

/**

//      kEditBoxInputFlagPassword: 
密码形式输入

//      kEditBoxInputFlagSensitive:
敏感数据输入、存储输入方案且预测自动完成

//      kEditBoxInputFlagInitialCapsWord:
每个单词首字母大写,并且伴有提示

//      kEditBoxInputFlagInitialCapsSentence:
第一句首字母大写,并且伴有提示

//      kEditBoxInputFlagInitialCapsAllCharacters:
所有字符自动大写

//     */

//设置返回类型

box->setReturnType(kKeyboardReturnTypeDone);

/**

//      kKeyboardReturnTypeDefault: 
默认使用键盘return 类型

//      kKeyboardReturnTypeDone:    
默认使用键盘return类型为“Done”字样

//      kKeyboardReturnTypeSend:    
默认使用键盘return类型为“Send”字样

//      kKeyboardReturnTypeSearch:  
默认使用键盘return类型为“Search”字样

//      kKeyboardReturnTypeGo:      
默认使用键盘return类型为“Go”字样

//      */

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

addChild(box);

CCScale9Sprite *sacel9SprG=CCScale9Sprite::create("green_edit.png");

,
), sacel9SprG);

box2->setInputFlag(kEditBoxInputFlagPassword);

box2->setReturnType(kKeyboardReturnTypeGo);

box2->);

box2->setPlaceHolder("请输入密码");

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

addChild(box2);

}

break;

:

{

CCScale9Sprite *sacel9SprG=CCScale9Sprite::create("green_edit.png");

,
), sacel9SprG);

box2->setPlaceHolder("Delegate");

box2->,));

addChild(box2);

box2->setDelegate(this);

}

break;

}

return true;

}

void
HelloWorld::editBoxEditingDidBegin(CCEditBox *editBox)

{

CCLOG("start edit");

}

void
HelloWorld::editBoxEditingDidEnd(CCEditBox *editBox)

{

CCLOG("end edit");

}

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

{

CCLOG("textchanged");

}

void
HelloWorld::editBoxReturn(CCEditBox *editBox)

{

CCLOG("editboxreturn");

}

(转) CCEditBox 编辑框的更多相关文章

  1. cocos2dx基础篇(13) 编辑框之二CCEditBox

    [3.x] (1)去掉"CC" (2)设置虚拟键盘的编辑类型 > EditBoxInputMode 变为强枚举 EditBox::EditBoxInputMode // SI ...

  2. cocos2dx基础篇(12) 编辑框之一CCTextFieldTTF

    前面我们讲了精灵贴图.标签.菜单.按钮.感觉似乎少了点什么?UI控件里是不是应该还有一个很重要的控件--编辑框.在手机网游中,启动游戏,过了开场动画后,基本上显示的第一个界面应该就是游戏的登录界面了吧 ...

  3. MFC编辑框字体大小调节(转)

    在学习MFC中需要调整编辑框中的字体大小,以下是我结合网上与自己实际操作总结的,希望对其它同学有所帮助.       首先,了解以下函数原型:BOOL CreateFont( int nHeight, ...

  4. MFC编程入门之二十一(常用控件:编辑框Edit Control)

    上一节讲了静态文本框,本节讲的是编辑框(Edit Control)同样是一种很常用的控件,我们可以在编辑框中输入并编辑文本.在前面加法计算器的例子中已经演示了编辑框的基本应用.下面具体讲解编辑框的使用 ...

  5. MFC 编辑框中字体大小改变,行高不能改变,只能显示一半的问题,已解决。

    CKagulaCEdit是CEdit的一个继承类,m_edit的CKagulaCEdit类型的一个变量 调用的时候,是这样的: 编辑框中字体大小改变,行高不能改变,只能显示一半的问题,问题如下: 这时 ...

  6. NGUI 使用EventDelegate.Add与UIInput.onSubmit、UIInput.onChange限定编辑框中的内容

    Unity中,使用NGUI,通常为某个控件(如按钮)绑定事件(单击.双击.拖拽.滚轮.选择等)都是用UIEventListener,比如: public void Bind() { UIEventLi ...

  7. java报表工具FineReport的SQL编辑框的语法简介

    感谢大家捧场,这里继续分享关于SQL编辑框的一些语法心得总结,因为数据集定义的面板,也是FineReport报表中最常用的模块之一. 1.我理解的执行过程. 这里其实是生成一个字符串,FineRepo ...

  8. java报表工具FineReport的公式编辑框的语法简介

    FINEREPORT用到公式的地方非常多,单元格(以=开头的便被解析为公式),条件显示,数据字典,报表填报属性值定义,图表标题,轴定义,页眉页脚,甚至单元格的其他属性中的鼠标悬浮提示内容都可以写公式, ...

  9. java报表工具FineReport的JS编辑框和URL地址栏语法简介

    JS编辑框: 1.FineReport的js. 作为一款BS产品,browser端的JavaScript是必不可少的. FineReport中的js是已经调用了finereport.js的. 大家知道 ...

随机推荐

  1. Javascript 中的一些关于时间的操作【转】

    1.时间对象和一些简单操作函数 var myDate = new Date(); myDate.getYear();       //获取当前年份(2位) myDate.getFullYear(); ...

  2. $_POST 变量以及$GLOBALS['HTTP_RAW_POST_DATA']

    $_POST 变量是一个数组,内容是由 HTTP POST 方法发送的变量名称和值. $_POST 变量用于收集来自 method="post" 的表单中的值.从带有 POST 方 ...

  3. Oracle登录操作系统验证和密码文件验证

    1.确认数据库版本 2.查看当前配置文件 ORALCE数据库不同的登录验证方式是和SQLNET.ORA配置文件有关系的,在配置文件中有一个参数sqlnet.authentication_service ...

  4. sql实现对多个条件分组排序方法和区别

    转自: http://blog.csdn.net/winer2008/article/details/4283539 rank,dense_rank,row_number区别 一:语法(用法):    ...

  5. Mariadb 10.1 joiner节点加入报错WSREP: Failed to prepare for incremental state transfer

    Mariadb 10.1 galera cluster 集群joiner 节点加入集群 会出现这种报错,导致mysql一直点点点,这里我贴出报错.2016年04月19日13:34:58 2016-04 ...

  6. 一整套WordPress模板制作的教程

    WordPress基本模板文件 一套完整的WordPress模板应至少具有如下文件:style.css: CSS(样式表)文件index.php : 主页模板archive.php : Archive ...

  7. canvas的默认尺寸

    canvas一直就是偶尔看看,随便画点小东西,没有认真琢磨过,今天打算认真的从头学一下,画线的时候感觉坐标不太正常,后来发现,canvas有自己的默认尺寸 写法如下 <canvas id=&qu ...

  8. 《UML大战需求分析》阅读笔记02

    软件应能真正的对客户的工作提供帮助,只有客户使用并真正对其有用才能说我们做的软件成功了.客户从开始提出需求时到后期的工作过程中,需求总是不停变化的,所以这就需要需求人员对需求领先于客户.所以活用UML ...

  9. iOS 用collectionview 做的无限图片滚动 广告banner适用

    使用方法见demo,bug未知,若有什么问题欢迎留言:) http://files.cnblogs.com/files/n1ckyxu/NickyScrollImageView.zip demo使用s ...

  10. 15.2 THE USE OF A LARGE REGISTER FILE

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION