cocos2dx-Lua中Label文本超过特定长度使用...代替

开发环境:cocos2dx 3.17
开发语言:lua
我们在开发过程中,经常会遇到字符串过长,显示的时候超出范围,我们可以用...来代替字符串后面的内容。

代码:

1
2
3
4
5
6
7
8
9
10
11
function getStrByLen(str, len)
if str == nil or len == nil then
return
end
local limitStr = str
if(string.len(limitStr) > len) then
local sName = SubUTF8String(limitStr , len)
return sName.."..."
end
return limitStr
end