cocos2dx之CCEditBox

上一篇文章是用到CCTextFieldTTF来创建的一个输入框,现在我们用CCEditBox来创建一个输入框,它是在2.0版本后加入的,好了,看例子吧:

 

CCEditBox *m_InputBox;


定义一个editbox;

 

void MyEditBoxLayer::initLayer() {
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCScale9Sprite *s9sprite = CCScale9Sprite::create("face.jpg");
	m_InputBox = CCEditBox::create(CCSizeMake(100, 50),
											s9sprite);
	m_InputBox->setAnchorPoint(ccp(0.5f, 0.5f));
	m_InputBox->setPosition(ccp(100, 200));
	this->addChild(m_InputBox, 1);
	m_InputBox->setColor(ccc3(255, 0, 0));
	m_InputBox->setText("so I Create an edit box");
	m_InputBox->setMaxLength(10); //这个在PC上没有作用的。
	m_InputBox->setOpacity(200);
	m_InputBox->setFontSize(10);
	//m_InputBox->setInputFlag(kEditBoxInputFlagPassword);
	m_InputBox->setInputMode(kEditBoxInputModeEmailAddr);

}


 kEditBoxInputFlagPassword, kEditBoxInputModeEmailAddr详解:

/**
 * \brief The EditBoxInputMode defines the type of text that the user is allowed
 * to enter.
 */
enum EditBoxInputMode
{
    /**
     * The user is allowed to enter any text, including line breaks.
     */
    kEditBoxInputModeAny = 0,
    
    /**
     * The user is allowed to enter an e-mail address.
     */
    kEditBoxInputModeEmailAddr,

    /**
     * The user is allowed to enter an integer value.
     */
    kEditBoxInputModeNumeric,

    /**
     * The user is allowed to enter a phone number.
     */
    kEditBoxInputModePhoneNumber,

    /**
     * The user is allowed to enter a URL.
     */
    kEditBoxInputModeUrl,

    /**
     * The user is allowed to enter a real number value.
     * This extends kEditBoxInputModeNumeric by allowing a decimal point.
     */
    kEditBoxInputModeDecimal,

    /**
     * The user is allowed to enter any text, except for line breaks.
     */
    kEditBoxInputModeSingleLine
};

/**
 * \brief The EditBoxInputFlag defines how the input text is displayed/formatted.
 */
enum EditBoxInputFlag
{
    /**
     * Indicates that the text entered is confidential data that should be
     * obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE.
     */
    kEditBoxInputFlagPassword = 0,

    /**
     * Indicates that the text entered is sensitive data that the
     * implementation must never store into a dictionary or table for use
     * in predictive, auto-completing, or other accelerated input schemes.
     * A credit card number is an example of sensitive data.
     */
    kEditBoxInputFlagSensitive,

    /**
     * This flag is a hint to the implementation that during text editing,
     * the initial letter of each word should be capitalized.
     */
    kEditBoxInputFlagInitialCapsWord,

    /**
     * This flag is a hint to the implementation that during text editing,
     * the initial letter of each sentence should be capitalized.
     */
    kEditBoxInputFlagInitialCapsSentence,

    /**
     * Capitalize all characters automatically.
     */
    kEditBoxInputFlagInitialCapsAllCharacters

};


 

创建成功!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值