local WIDTH = 300
local pageView = ccui.PageView:create()
pageView:setAnchorPoint(cc.p(0.5, 0.5))
pageView:setContentSize(cc.size(WIDTH, WIDTH))
pageView:center():addTo(self)
pageView:setBackGroundColorType(ccui.LayoutBackGroundColorType.solid)
pageView:setBackGroundColor(cc.c3b(0, 120, 0))
for i = 1, 6 do
local txt = ccui.Text:create("It's page" .. i - 1, "", 30)
txt:pos(WIDTH/2, WIDTH/2)
if i <= 3 then
local _layout = ccui.Layout:create()
_layout:setContentSize(WIDTH, WIDTH)
txt:addTo(_layout)
pageView:addPage(_layout)
else
pageView:addWidgetToPage(txt, i, true)
end
end
pageView:scrollToPage(3)
pageView:setCustomScrollThreshold(WIDTH/3)
pageView:addEventListener(function(sender, event)
if event == ccui.PageViewEventType.turning then
print("current page " .. pageView:getCurPageIndex())
end
end)