quick -- 添加按鈕

    cc.ui.UIPushButton.new({ normal = "comm_btnGreenBackBack.png", pressed = "comm_btnGreenBackBack_sel.png" })
        :onButtonClicked(function()
            print("start")
        end)
        :pos( display.cx / 2, display.cy )
        :addTo(self)

在Quick中有三種不一樣的Button控件,分別是:UIPushButton (按鈕控件)、UICheckBoxButton ( CheckButton 控件)和 UICheckBoxButtonGroup ( CheckButton 組控件)。ui

其中 UIPushButton 是最經常使用的按鈕控件,它繼承自UIButton,咱們能夠經過 cc.ui.UIPushButton.new(images, options) 方法來建立 UIPushButton。參數 images 是 table 類型,它表明各個按鈕狀態(正常、按下、禁用)下的圖片;options 爲可選參數,也是 tabl e類型,包含了是否scale9縮放,偏移flipX、flipY值等設置。spa

onButtonClicked 方法用於監聽按鈕的點擊事件,當點擊按鈕時,將調用該方法中的代碼。如上例中,當咱們點擊按鈕時,會在控制檯窗口中打印「start」的字段。同 onButtonClicked 方法相似的還有:翻譯

  • onButtonPressed(callback):用於監聽按鈕的按下事件
  • onButtonRelease(callback):用於監聽按鈕的釋放事件
  • onButtonStateChanged(callback):用於監聽按鈕的狀態改變事件
相關文章
相關標籤/搜索