基本控件使用(二)(ScrollView,TableView)

基本控件使用(二)(ScrollView,TableView),第1张

概述今天主要讲解一下ScrollView和TableView控件的使用,话不多说,直接贴代码: 1、ScrollView: local scrollView = cc.ScrollView:create() -- local function scrollViewDidZoom() --                print("ScrollViewDidZoom") -- end -- local

今天主要讲解一下ScrollVIEw和tableVIEw控件的使用,话不多说,直接贴代码:

1、ScrollVIEw:

local scrollVIEw = cc.ScrollVIEw:create()

-- local function scrollVIEwDIDZoom()

-- print("ScrollVIEwDIDZoom")

-- end

-- local function scrollVIEwDIDScroll()

-- print("ScrollVIEwDIDScroll")

-- end

local layercolor = cc.Layercolor:create(cc.c4b(100,100,100),700,600)

scrollVIEw:setVIEwSize(cc.size(700,300))

scrollVIEw:setContainer(layercolor)

layercolor:setposition(cc.p(0,0))

scrollVIEw:setposition(cc.p(50,50))

bg:addChild(scrollVIEw)

scrollVIEw:setDirection(cc.SCRolLVIEW_DIRECTION_VERTICAL)--垂直滚动

--cc.SCRolLVIEW_DIRECTION_HORIZONTAL 水平滚动

--cc.SCRolLVIEW_DIRECTION_BOTH 垂直水平滚动

scrollVIEw:setBounceable(true)

--scrollVIEw:setDelegate()

--scrollVIEw:registerScriptHandler(scrollVIEwDIDZoom,cc.SCRolLVIEW_SCRIPT_ZOOM)

--scrollVIEw:registerScriptHandler(scrollVIEwDIDScroll,cc.SCRolLVIEW_SCRIPT_SCRolL)

for i = 1,6 do

localstrFmt = string.format("第%d行",i)

locallabel = cc.Label:createWithSystemFont(strFmt,"Arial",32)

label:setcolor(cc.c3b(255,0))

label:setposition(cc.p(350,600-i*100+50))

layercolor:addChild(label)

end


2、tableVIEw

local function scrollVIEwDIDScroll(vIEw)
print("ScrollVIEwDIDScroll")
end
local function scrollVIEwDIDZoom(vIEw)
print("ScrollVIEwDIDZoom")
end
local function tableCelltouched(table,cell)
print("cell touched at index: "..cell.getIDx())
end
local function cellSizefortable(table,IDx)
return 60,60
end
local function tableCellAtIndex(table,IDx)
local strValue = string.format("%d",IDx)
local cell = table:dequeueCell()
local label = nil
if nil == cell then
cell = cc.tableVIEwCell:create()
label = cc.Label:createWithSystemFont(strValue,32)
label:setposition(cc.p(0,0))
label:setAnchorPoint(cc.p(0,0))
cell:addChild(label)
label:setTag(123)
else
label = cell:getChildByTag(123)
if label ~= nil then
label:setString(strValue)
end
end
return cell
end
local function numberOfCellsIntableVIEw(table)
return 20
end
local tableVIEw = cc.tableVIEw:create(cc.size(700,300))
tableVIEw:setposition(cc.p(50,40))
tableVIEw:setDelegate()
tableVIEw:setDirection(cc.SCRolLVIEW_DIRECTION_VERTICAL)
bg:addChild(tableVIEw)
tableVIEw:registerScriptHandler(scrollVIEwDIDScroll,cc.SCRolLVIEW_SCRIPT_SCRolL)
tableVIEw:registerScriptHandler(scrollVIEwDIDZoom,cc.SCRolLVIEW_SCRIPT_ZOOM)
tableVIEw:registerScriptHandler(tableCelltouched,cc.tableCELL_touchED)
tableVIEw:registerScriptHandler(cellSizefortable,cc.tableCELL_SIZE_FOR_INDEX)
tableVIEw:registerScriptHandler(tableCellAtIndex,cc.tableCELL_SIZE_AT_INDEX)
tableVIEw:registerScriptHandler(numberOfCellsIntableVIEw,cc.NUMBER_OF_CELLS_IN_tableVIEW)

tableVIEw:reloadData()


关于ScrollVIEw和tableVIEw的使用大概就是这样,会用就可以了。

总结

以上是内存溢出为你收集整理的基本控件使用(二)(ScrollView,TableView)全部内容,希望文章能够帮你解决基本控件使用(二)(ScrollView,TableView)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1081000.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存