用户输入账号和password输入是常见工能,如今用editbox来实现username和password输入。可是这个商业项目上常见功能,网上却没有找到教程。我就一步一步的实现。代码例如以下:
-
function MainScene:ctor()
ui.newTTFLabel({text = "User Login", size = 20, align = ui.TEXT_ALIGN_CENTER})
:pos(display.cx, display.cy+50)
:addTo(self)
------
local function onEdit(event, editbox)
if event == "began" then
-- 開始输入
elseif event == "changed" then
-- 输入框内容发生变化
elseif event == "ended" then
-- 输入结束
elseif event == "return" then
-- 从输入框返回
end
end
local editbox = ui.newEditBox({
image = "EditBox.png",
listener = onEdit,
size = CCSize(200, 40)
})
editbox:pos(display.cx, display.cy)
editbox:addTo(self)
--------
local editbox2 = ui.newEditBox({
image = "EditBox.png",
listener = onEdit,
size = CCSize(200, 40)
})
--设置password输入框
editbox2:setInputFlag(0)
editbox2:pos(display.cx, display.cy/2)
editbox2:addTo(self)
--------------
end - setInputFlag(0) 是实现password输入
- EditBox.png 要做成一个小的图片,然后用九风格来不变形拉伸