local editbox_account = ccui.EditBox:create(cc.size(dark_bg:getContentSize().width,dark_bg:getContentSize().height), ccui.Scale9Sprite:create(),nil,nil)
editbox_account:setFontColor(cc.c3b(0,0,0))
editbox_account:setText("1")
editbox_account:setReturnType(cc.KEYBOARD_RETURNTYPE_DONE )
editbox_account:setAnchorPoint(0.5,0.5)
editbox_account:setMaxLength(30)
editbox_account:setPosition(dark_bg:getContentSize().width/2, dark_bg:getContentSize().height/2)
editbox_account:setPlaceholderFontColor(cc.c3b(255,255,255))
editbox_account:setFontName("Helvetica")
editbox_account:setPlaceholderFontName("Helvetica")
editbox_account:setFontSize(24)
editbox_account:setPlaceholderFontSize(24)
editbox_account:setInputMode(cc.EDITBOX_INPUT_MODE_NUMERIC)
dark_bg:addChild(editbox_account)
editbox_account:setHACenter()
count_num = tonumber(editbox_account:getText())
count_label:setString(editbox_account:getText())
获取的是setTExt里的内容,怎么让他得到的是输入的的内容?
编辑框加上去了,点击的时候会弹出一个 input 对话框,
还有个问题怎么能让它不弹出输入框直接输入文字?
获取输入框的内容可用在注册的回调函数中调用_editBox:getText(),就像下面这样:
local _editBox = nil
local function editBoxTextEventHandle( event )
local filter = string.lower(_editBox:getText())
if string.len(filter) > 0 then
end
end
_editBox = ccui.EditBox:create(size, ccui.Scale9Sprite:create(),ccui.Scale9Sprite:create(),ccui.Scale9Sprite:create())
_editBox:setAnchorPoint(0,0.5)
_editBox:setPosition(-435,245)
_editBox:setFontColor(cc.c4b(0,0,0,255))
--注册脚本回调函数
_editBox:registerScriptEditBoxHandler(editBoxTextEventHandle)
node:addChild(_editBox,1)
脚本回调函数:
local function editboxEventHandler(eventType)
if eventType == "began" then
-- triggered when an edit box gains focus after keyboard is shown
--当editbox获取焦点时调用
elseif eventType == "ended" then
-- triggered when an edit box loses focus after keyboard is hidden.
--当editbox失去焦点时调用
elseif eventType == "changed" then
-- triggered when the edit box text was changed.
--当editbox中的内容改变时调用
elseif eventType == "return" then
-- triggered when the return button was pressed or the outside area of keyboard was touched.
--当按了return按钮或者键盘外的区域时调用
end
end