因为找不到教程,所以就只能自己写了一个简单的,献给和我一样的菜鸟
local function onEdit(event, editbox)
if event == "began" then
-- 开始输入
elseif event == "changed" then
-- 输入框内容发生变化
elseif event == "ended" then
-- 输入结束
len = #(string.gsub(editbox:getText() , "\128-\191]" , ""))
--计算输入的字符数
if len > 12 then
print("So Long")
end
elseif event == "return" then
-- 从输入框返回
end
end
local editbox = ui.newEditBox({
image = "ui/Editbox.png",
listener = onEdit,
x = display.cx + 30 ,
y = display.cy ,
size = CCSize(300 , 60)
})
editbox:addTo(self)
editbox:setFontColor(cc.c3b(255 , 255 , 0))
```