How to change display.newText align style?

Hi all, 

I found that display.newText’s text align style is middle.

Can I change it to the left or right?

Please help.

Thanks

For single line text, the idea of alignment isn’t that important.  You can use a combination of reference points and x, y to move it where you need it.  If you change the text later by setting it’s .text property and it changes the size of the box, then yes, that is center aligned and you really can’t change it other than changing reference point and the x, y.  For instance, lets say you want a piece of text to be left justified to 100, 100

local myText = display.newText(“Hello World”, 100, 100, native.systemFont, 20)

With most Corona SDK display objects, when you put an X, Y in the parameter list, it’s assumed to be a “Top Left” reference.  However the instant the call is over, any changes to its .x and .y values are from the object’s center.   Changing the text property, as I said above will cause the new box to be adjusted around the center point.  To fix this:

myText.text = “Hello World, Welcome to Corona”

myText:setReferencePoint(display.TopLeftReferencePoint)

myText.x = 100

myText.y = 100

solves the problem.

If you are doing multi-line text, we do support alignment.  See:

http://docs.coronalabs.com/api/library/display/newText.html

Now you probably could specify a width for your text, to force it to be in multi-line mode and left justified and just make sure your text doesn’t get too big to wrap.

Thank you, I will try

For single line text, the idea of alignment isn’t that important.  You can use a combination of reference points and x, y to move it where you need it.  If you change the text later by setting it’s .text property and it changes the size of the box, then yes, that is center aligned and you really can’t change it other than changing reference point and the x, y.  For instance, lets say you want a piece of text to be left justified to 100, 100

local myText = display.newText(“Hello World”, 100, 100, native.systemFont, 20)

With most Corona SDK display objects, when you put an X, Y in the parameter list, it’s assumed to be a “Top Left” reference.  However the instant the call is over, any changes to its .x and .y values are from the object’s center.   Changing the text property, as I said above will cause the new box to be adjusted around the center point.  To fix this:

myText.text = “Hello World, Welcome to Corona”

myText:setReferencePoint(display.TopLeftReferencePoint)

myText.x = 100

myText.y = 100

solves the problem.

If you are doing multi-line text, we do support alignment.  See:

http://docs.coronalabs.com/api/library/display/newText.html

Now you probably could specify a width for your text, to force it to be in multi-line mode and left justified and just make sure your text doesn’t get too big to wrap.

Thank you, I will try