EditBox

来源:互联网 发布:软件开发外包管理制度 编辑:程序博客网 时间:2024/06/05 08:05
local  sprite = ccui.Scale9Sprite:create(activeLayer:addImgFile(string.format("%sad_activity_codebg.png", activePath)))
local codeInput = ccui.EditBox:create(cc.size(350, 50), sprite,sprite,sprite)
codeInput:setPlaceholderFont(activeLayer:GetTtfFont(), 24)
codeInput:setFont(activeLayer:GetTtfFont(), 24)
if appLoc ~= 1 and appLoc ~= 16 then
    codeInput:setPlaceholderFont(activeLayer:GetTtfFont(), 22)
    codeInput:setFont(activeLayer:GetTtfFont(), 22)
end
codeInput:setPlaceHolder(getLocalString("input_tip", appLoc));
codeInput:setFontColor(cc.c3b(255, 255, 255))
codeInput:setMaxLength(24)
codeInput:setPosition(cc.p(cPosX,150))    
bgSprite:addChild(codeInput)


local function editboxEventHandler(eventType)
        if eventType == "began" then --编辑框开始编辑时调用
            strFmt = string.format("editBox %p DidBegin !", codeInput)
            print(strFmt)
        elseif eventType == "ended" then --编辑框完成时调用
            strFmt = string.format("editBox %p DidEnd !", codeInput)
            print(strFmt)
        elseif eventType == "return" then --编辑框return时调用
            strFmt = string.format("editBox %p was returned !",codeInput)
            --判断是哪个编辑框,在多个编辑框同时绑定此函数时 需判断时哪个编辑框
            if codeInput == EditName then 
              --当编辑框EditName 按下return 时到此处
            elseif codeInput == EditPassword then
            --当编辑框EditPassword  按下return 时到此处
            elseif codeInput == EditEmail then
            --当编辑框EditEmail   按下return 时到此处
            end
            print(strFmt)
        elseif eventType == "changed" then --编辑框内容改变时调用
            strFmt = string.format("editBox %p TextChanged, text: %s ", codeInput, codeInput:getText())
            print(strFmt)
        end
end
codeInput:registerScriptEditBoxHandler(editboxEventHandler)
原创粉丝点击