EditBox
蔡晨
2023-12-01
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)