自适应ccui.Text大小

2019-05-24  本文已影响0人  Wintersnowcream

--玩法名字自适应居中

function UISwitchcircleGrupLayer:playsTextAdaptation(textObj,str)

    -- body

    --文本框固定宽度

    local fixed_width = 310

    --文本变化宽度

    local obj_size = textObj:getContentSize()

    --字体大小

    local font_size = textObj:getFontSize()

    --字体间间隔

    local interval_width = 1

    local interval_height = 2

    local n = math.ceil(obj_size.width / fixed_width)

    if obj_size.width >= fixed_width then

        --todo

        --自适应宽度设置false,再设置文本大小

        textObj:ignoreContentAdaptWithSize(false)

        textObj:setContentSize(cc.size(fixed_width,(font_size + interval_height) * math.ceil(obj_size.width / fixed_width)))

    end

end

上一篇 下一篇

猜你喜欢

热点阅读