1. EditBox사용할 Layer의 Head를 다음과 같이 설정한다.
#ifndef __ProjectName__MemberLayer__ #define __ProjectName__MemberLayer__ #include "Common.h" #include "cocos-ext.h" // EditBox사용을 위한 추가 USING_NS_CC_EXT; // EditBox사용을 위한 추가 // CCEditBoxDelegate 추가 class MemberLayer:public CCLayer, public CCEditBoxDelegate { public: virtual bool init(); static CCScene* scene(); CREATE_FUNC(MemberLayer); /////////////////////////////////////////////////////////////// // EditBox사용을 위한 추가 시작 /////////////////////////////////////////////////////////////// virtual void editBoxEditingDidBegin(CCEditBox* editBox); virtual void editBoxEditingDidEnd(CCEditBox* editBox); virtual void editBoxTextChanged(CCEditBox* editBox, const std::string& text); virtual void editBoxReturn(CCEditBox* editBox); /////////////////////////////////////////////////////////////// // EditBox사용을 위한 추가 끝 /////////////////////////////////////////////////////////////// private: void PrepareResources();// 본 페이지에서 사용할 리소스 로드 void StartLayout(); // 전체 레이아웃 구성 void PrepareEditBox(); // 이름, 생년월일, 비밀번호 입력 텍스트박스 생성 CCSpriteBatchNode* batchNode; CCEditBox* Name; // 이름을 입력할 텍스트박스 CCEditBox* Birth; // 생년월일을 입력할 텍스트박스 CCEditBox* Pwd; // 비밀번호를 입력할 텍스트박스 }; #endif /* defined(__ProjectName__MemberLayer__) */
2. cpp 파일
#pragma mark - #pragma mark EditBox void MemberLayer::PrepareEditBox() { /***************************************************************** * 이름 필드 ****************************************************************/ Name = CCEditBox::create(CCSizeMake(300, 50), CCScale9Sprite::createWithSpriteFrameName("editBox_bg_normal.png")); Name->setPosition(Common::centerPoint()); Name->setFontColor(ccRED); Name->setPlaceHolder("Name"); Name->setPlaceholderFontColor(ccWHITE); Name->setReturnType(kKeyboardReturnTypeDefault); Name->setInputMode(kEditBoxInputModeAny); Name->setTag(1); Name->setDelegate(this); this->addChild(Name); /***************************************************************** * 생년월일 필드 ****************************************************************/ Birth = CCEditBox::create(CCSizeMake(300, 50), CCScale9Sprite::createWithSpriteFrameName("editBox_bg_complete.png")); Birth->setPosition(ccpAdd(Name->getPosition(), ccp(0, 100))); Birth->setFontColor(ccRED); Birth->setInputMode(kEditBoxInputModePhoneNumber); Birth->setDelegate(this); this->addChild(Birth); /***************************************************************** * 비밀번호 필드 ****************************************************************/ Pwd = CCEditBox::create(CCSizeMake(300, 50), CCScale9Sprite::createWithSpriteFrameName("editBox_bg_error.png")); Pwd->setPosition(ccpAdd(Birth->getPosition(), ccp(0, 100))); Pwd->setFontColor(ccRED); Pwd->setInputMode(kEditBoxInputModePhoneNumber); Pwd->setTag(3); Pwd->setReturnType(kKeyboardReturnTypeDone); Pwd->setInputFlag(kEditBoxInputFlagPassword); Pwd->setDelegate(this); this->addChild(Pwd); } #pragma mark - #pragma mark EditBox Virtual Methods void MemberLayer::editBoxEditingDidBegin(cocos2d::extension::CCEditBox *editBox) { // EditBox편집이 시작될 때 발생하는 이벤트 } void MemberLayer::editBoxEditingDidEnd(cocos2d::extension::CCEditBox *editBox) { // EditBox편집이 끝날 때 발생하는 이벤트 } void MemberLayer::editBoxTextChanged(cocos2d::extension::CCEditBox *editBox, const std::string &text) { // EditBox내 Text가 변경될 때 발생하는 이벤트 } void MemberLayer::editBoxReturn(cocos2d::extension::CCEditBox *editBox){}
EditBoxInputMode (EX) setInputMode(kEditBoxInputModeAny))
- kEditBoxInputModeAny = 0,
- kEditBoxInputModeEmailAddr,
- kEditBoxInputModeNumeric,
- kEditBoxInputModePhoneNumber,
- kEditBoxInputModeUrl,
- kEditBoxInputModeDecimal,
- kEditBoxInputModeSingleLine
EditBoxInputFlagType (EX) setInputFlag(kEditBoxInputFlagPassword))
- kEditBoxInputFlagPassword = 0,
- kEditBoxInputFlagSensitive,
- kEditBoxInputFlagInitialCapsWord,
- kEditBoxInputFlagInitialCapsSentence,
- kEditBoxInputFlagInitialAllCharacters
KeyboardReturnType (EX) setReturnType(kKeyboardReturnTypeSend))
- kKeyboardReturnTypeDefault = 0,
- kKeyboardReturnTypeDone,
- kKeyboardReturnTypeSend,
- kKeyboardReturnTypeSearch,
- kKeyboardReturnTypeGo
댓글 없음:
댓글 쓰기