UIPageView

local ui=require("framework.ui")
local MainScene = class("MainScene", function()
return display.newScene("MainScene")
end)

function MainScene:ctor()
-- cc.ui.UILabel.new({
-- UILabelType = 2, text = "Hello, World", size = 64})
-- :align(display.CENTER, display.cx, display.cy)
-- :addTo(self)
--不同label的创建方法;
-- local label=display.newTTFLabel({
-- text="龙日天",
-- size=70
-- })
local label=ui.newTTFLabel({
text="龙日天",
size=80,
color=cc.c3b(255, 0, 0)
})
label:setPosition(display.cx, display.cy)
label:addTo(self)
--UIPageView的使用
self.pv = cc.ui.UIPageView.new({
viewRect = cc.rect(0,0,960,640) , --设置位置和大小
column = 3 , row = 3, --列和行的数量
padding = {left = 20 , right = 20 , top = 20 , bottom = 20} , --整体的四周距离
columnSpace = 10 , rowSpace = 10 --行和列的间距
})
--[[ 实际上,除了 C++ 回调 Lua 函数之外,在其他所有需要回调的地方都可以使用 handler()。
@param mixed obj Lua 对象
@param function method 对象方法
@return function

function handler(obj, method)
return function(...)
return method(obj, ...)
end
end
]]
:onTouch(handler(self,self.touchListener))--handler调用回调函数;
:addTo(self)

for i = 1 , 27 do
-- 创建一个新的页面控件项
-- @function [parent=#UIPageView] newItem
-- @return UIPageViewItem#UIPageViewItem
local item = self.pv:newItem()
local content
content = display.newColorLayer(
cc.c4b(math.random(250),
math.random(250),
math.random(250),
math.random(250)))

content:setContentSize(240,140)
content:setTouchEnabled(false)
item:addChild(content) -- 为每个单独的item添加一个颜色图块
self.pv:addItem(item) --为pageview添加item
end

self.pv:reload() --需要重新刷新才能显示
-- self:copyJson()
end
function MainScene:touchListener(event)
dump(event, "TestUIPageViewScene - event")
local listView =event.listView
if 3 == event.itemPos then
listView:removeItem(event.item,true)
print("longyongzhi")
end

end
function MainScene:onEnter()
end

function MainScene:onExit()
end

return MainScene

原文链接: https://www.cnblogs.com/xiajianwei/p/5122331.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    UIPageView

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/227197

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 下午1:31
下一篇 2023年2月13日 下午1:31

相关推荐