1.定義ui表結構 local ui ={}
1) 定義一些·全局變量ui.DEFAULT_TTF_FONT = "Arail" ui.DEFAULT_TTF_FONT_SIZE = 24
2)一些可用控件
(1) ui.newEditBox(params)
參數:image(初始狀態),imagePressed(輸入狀態),imageDisabled(禁用狀態),listener(回調函數),size(使用size = cc,size(高度,寬度) ) ,x.y 座標
· 例子:local function onEdit(event,editBox)
if event == "began" then --開始輸入
elseif event == "changed" then --輸入框狀態改變
elseif event =="ended" then --輸入結束
elseif event == "return" then --從輸入框返回
end
local editBox = ui.newEditBox({
image="editbox.png",
listener="onEdit",
size = cc.size(200,40)
}) setInputFlag(0) 設置爲密碼輸入 setPlaceHodler("") 顯示初始文本 setText("") 出現輸入法後默認文本
(2) ui.newTextField()與newEditBox類似 params.UIInputType = 2 而 editBox params.UIInputType = 1
(3)ui.newBMFontLabel(params) 使用位圖文字創建文本顯示對象 返回LabelBMFont 常用於顯示英文文字,顯示中文要使用TTFLabel
參數:text,font,align,x,y
············(4)ui.newTTFLabel(params) 使用ttf字體創建文字顯示對象,並返回LabelTTF對象
參數:text,font,size,color,align,valign(文字的垂直對齊方式)dimensions(文字顯示對象的尺寸 使用 cc.size(width,height) 設置)x,y
local ttfLabel = ui.newTTFLabel({
text="aaa",
font="Arials",
size=64,
color=cc.c3b(255,0,0),
align= ui.TEXT_ALIGN_LEFT,
valign = ui.....TOP,
dimensions=cc.size(400,200)
})
(5)ui.newTTFLabelWithShadow(params) 創建帶陰影的文字對象並返回TTF 比newTTFLabel多一個參數
shadowColor = cc.c4b()
(6)ui.newTTFLabelWithOutline(params) 創建帶描邊的TTF文字顯示對象 ,並返回LabelTTF 相比TTFLabel增加一個參數
outlineColor=cc.c4b()