I’ve encountered a problem when I tried to rely on a text object height to position elements in the UI.
Strangely enough when I ask a multiline text object for its contentHeight I get the height for a single line. If I ask again after a short timer, I get the correct value.
local pLabel = { text=text, --long text x=x, y=y, width = w, align = align or "left", font=fontName, fontSize=fontSize, } local label = display.newEmbossedText(pLabel) label.anchorX = 0.0 parent:insert(label) print("Label", text, w, label.contentHeight) timer.performWithDelay(10, function() print("Label2", text, w, label.contentHeight) end)
The code above illustrates the issue quite well. Does the text object manipulates itself to multiple lines using some delay so its height is not updated on its creation? I did not see this issue before.