zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    再学 GDI+[38]: 文本输出 DrawString、TGPFont
    再学 GDI+[42]: 文本输出 字号单位
    再学 GDI+[41]: 文本输出 控制输出字符的个数
    再学 GDI+[45]: 文本输出 文本呈现质量
    博客园电子期刊2008年11月半月刊(上)发布啦
    博客园电子期刊2008年12月●半月刊(上)发布啦
    招聘频道功能更新:RSS订阅
    博客园新版招聘频道(job.cnblogs.com)上线测试啦
    《悟透JavaScript》到货了
    博客园电子期刊2008年11月●半月刊(下)发布啦
  • 原文地址:https://www.cnblogs.com/xiajianwei/p/5122331.html
Copyright © 2011-2022 走看看