cocos2dx之CCEditBox

来源:互联网 发布:手机时时彩看号软件 编辑:程序博客网 时间:2024/05/16 03:24

上一篇文章是用到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};


 

创建成功!
0 0
原创粉丝点击