cocos2d-lua 3.10 用代碼創(chuàng)建一個(gè)9宮格按鈕

    local function touchEvent(sender,eventType)
        if eventType == ccui.TouchEventType.began then
            textButton:setTitleText("Touch Down")
        elseif eventType == ccui.TouchEventType.moved then
            textButton:setTitleText("Touch Move")
        elseif eventType == ccui.TouchEventType.ended then
            textButton:setTitleText("Touch Up")
        elseif eventType == ccui.TouchEventType.canceled then
            textButton:setTitleText("Touch Cancelled")
        end
    end

    local textButton = ccui.Button:create()
    textButton:setTouchEnabled(true)
    textButton:setScale9Enabled(true)
    textButton:loadTextures("px_ui_61.png", "px_ui_62.png", "", ccui.TextureResType.plistType)
    textButton:setCapInsets(cc.rect(20,10,textButton:getVirtualRendererSize().width-40,textButton:getVirtualRendererSize().height-20))--設(shè)置9宮格的邊角參數(shù) 第一個(gè)是寬度起始 第二個(gè)是高度起始 第三個(gè)是寬度拉伸距離 第四個(gè)是高度拉伸距離
    textButton:setContentSize(cc.size(180, textButton:getVirtualRendererSize().height * 1.5))--設(shè)置完參數(shù)后必須調(diào)用這個(gè)設(shè)置最終大小
    textButton:setTitleText("Text Button scale9 render")
    textButton:setTitleFontSize(30)
    textButton:setPosition(cc.p(display.width / 2.0, display.height / 2.0))
    textButton:addTouchEventListener(touchEvent)
    self._uiLayer:addChild(textButton)

textButton:setCapInsets(cc.rect(20,10,textButton:getVirtualRendererSize().width-40,textButton:getVirtualRendererSize().height-20))--設(shè)置9宮格的邊角參數(shù) 第一個(gè)是寬度起始 第二個(gè)是高度起始 第三個(gè)是寬度拉伸距離 第四個(gè)是高度拉伸距離
textButton:setContentSize(cc.size(180, textButton:getVirtualRendererSize().height * 1.5))--設(shè)置完參數(shù)后必須調(diào)用這個(gè)設(shè)置最終大小

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 前言: 在接觸Android這么長(zhǎng)時(shí)間,看到很多大牛都在和大家分享自己的知識(shí),深有體會(huì),剛好前段時(shí)間寫(xiě)了一個(gè)Dem...
    楊艷偉閱讀 1,383評(píng)論 0 5
  • ¥開(kāi)啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開(kāi)一個(gè)線程,因...
    小菜c閱讀 7,355評(píng)論 0 17
  • 一:canvas簡(jiǎn)介 1.1什么是canvas? ①:canvas是HTML5提供的一種新標(biāo)簽 ②:HTML5 ...
    GreenHand1閱讀 4,882評(píng)論 2 32
  • 選擇qi:是表達(dá)式 標(biāo)簽選擇器 類(lèi)選擇器 屬性選擇器 繼承屬性: color,font,text-align,li...
    wzhiq896閱讀 2,126評(píng)論 0 2
  • 在這社會(huì)日漸競(jìng)爭(zhēng)激洌的情況下為了完成生存能力必須學(xué)習(xí) 從三個(gè)方面來(lái)學(xué)習(xí)一是思維能力就是如何做好一個(gè)事來(lái)進(jìn)行規(guī)劃最終...
    鮑詠梅閱讀 175評(píng)論 0 1

友情鏈接更多精彩內(nèi)容