一个设置button上字体的封装

来源:互联网 发布:数字软件下载 编辑:程序博客网 时间:2024/05/21 23:00
function funcSetButtonText(btn,text1,color,flag,fontSize,text_position)
    --    tolua.cast(btn,"Button")
    -- if not flag then
    --     if text1 ==language(120) then
    --         return
    --     end
    -- end




    local ttf
    if btn:getChildByTag(3251) then
        btn:removeChildByTag(3251,true)
    end


    -- ttf = ccui.TextBMFont:create()
    -- ttf:setFntFile("Fnt/fnt_01.fnt")
    ttf=ccui.Text:create()
    ttf:setFontName("FZYHJW--GB1-0.ttf")
    ttf:setFontSize(fontSize and fontSize or 20)
    ttf:enableOutline(cc.c3b(0,0,0),2)
    if text_position then
        ttf:setPosition(text_position)
    else
        ttf:setPosition(cc.p( btn:getVirtualRendererSize().width/2, btn:getVirtualRendererSize().height/2))
    end
    btn:addChild(ttf,20)


    ttf:setString(text1)
    if color then
        ttf:setColor(color)
    else
        ttf:setColor(cc.c3b(254,251,104))
    end
    ttf:setTag(3251)
    ttf:stopAllActions()
    btn:setPressedActionEnabled(false)


    return ttf
end
0 0
原创粉丝点击