如图是一个pageView,下面有显示总页数和当前页面的指针。
指针代码实现:首先添加n(页面总数)个图片,以表示页面总数。再添加一个显示当前页面的指针图片,默认显示到第一页,指针内可写一个函数接收参数Index(即第几页,Index可通过pageView的触摸event获得),然后通过此函数设置指针的位置。
代码:
local indicators = class("indicators", function()
return display.newNode()
end)
INDICATOR_MARGIN = 30
function indicators:ctor(numPages)
local x = display.cx - INDICATOR_MARGIN * (numPages - 1) / 2
local y = 100
self.indicator_ = display.newSprite("#LevelListsCellSelected.png")
self.indicator_:setPosition(x, y)
self.indicator_.firstX_ = x
self:addChild(self.indicator_)
for pageIndex = 1, numPages do
local icon = display.newSprite("#LevelListsCellIndicator.png")
icon:setPosition(x, y)
self:addChild(icon)
x = x + INDICATOR_MARGIN
end
end
function indicators:setSelected(Index)
transition.stopTarget(self.indicator_)
local x = self.indicator_.firstX_ + (Index - 1) * INDICATOR_MARGIN
self.indicator_:setPositionX(x)
end
return indicators