One sure way to get the exact size of text, is to create the text, and check it’s size…
If it’s too big, resize it (change font size, etc).
In the following case, I am creating a text object of a fixed width, and am later checking the height to see if it’s too big.
local messageText = display.newText( messages[i].MESSAGE, 0, 0, rowWidth, 0, native.systemFont, 32 ) -- height 0, and system sets it to actual height generated
if( messageText.height \> 100 ) then -- Is it too big\>
-- change font size, regenerate text... do in a loop if you want to...
end
I’m actually doing something different with my code – I’m measrung the height of my text, and then building some UI elements around it (tableView rows), but I’ve got a limit on how large they each will get… But anywho, getting the height of the text is key to a lot of the formatting.
[import]uid: 79933 topic_id: 32904 reply_id: 130755[/import]