I have created a working function to do this.
Here’s the code if someone is also looking for this:
function writeTitleLabel(g,x,y,txt, maxwidth)
local title = display.newText( txt, 0, 0, native.systemFontBold, 13*2 )
title:setTextColor(0,0,0)
g:insert(title)
title.y = y
title.xScale = 0.5
title.yScale = 0.5
if maxwidth and title.width > maxwidth then
local aantal = 1
while true do
title.text = string.sub(txt, 0,aantal) … “…”
if(title.contentWidth >= maxwidth) then
break
elseif(aantal >= string.len(txt)) then
break
end
aantal = aantal + 1
end
end
title.x = title.contentWidth * 0.5 + x
end [import]uid: 13464 topic_id: 7792 reply_id: 27828[/import]
I’m trying this but it is not working and I don’t know why? Any idea for the begginners?
[code]
local movieName = display.newText(“Onde os fracos não tem vez”, 50, 100, native.systemFontBold, 14)
local addPoints = (movieName.contentWidth > 100)
– remove last char while it is big
while movieName.contentWidth > 100 do
movieName.text = string.sub(movieName.text, 1, string.len(movieName.text)-1)
end
– add the points
if addPoints then
movieName.text = movieName.text … " …"
end
[/code] [import]uid: 6732 topic_id: 7792 reply_id: 33650[/import]