美文网首页
自适应ccui.Text大小

自适应ccui.Text大小

作者: Wintersnowcream | 来源:发表于2019-05-24 14:04 被阅读0次

--玩法名字自适应居中

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

相关文章

网友评论

      本文标题:自适应ccui.Text大小

      本文链接:https://www.haomeiwen.com/subject/tbugzqtx.html