Display.newtext() "\n" (Newline) Not Working On Ios ?

I found this blog from

October 13, 2011

Multiple Lines in display.newText()

Guess there is a typo in the explanation stating that “n” is used for newline (it should be “\n”, right?).

The problem is “\n” is not working on the device (iPhone 4) but it works in the simulator (Windows).

Can someone put more lights on this ?

Thank you!

What version of Corona SDK are you using?

Daily Build 1025

Off Topic :
 I wrote a multi-line library some time back which allows for center aligning each line of the multi-line text…
Give it a try if interested  :slight_smile:

http://developer.coronalabs.com/code/useful-multiline-text-library

Thank you Satheesh sounds interesting, will give it a try if Corona stuff confirms the “\n” is not working.

Can anyone confirm if the “\n” is working or not on the iPhone ?

You have to tell display.newText that you want multi line text:

t = display.newText(“This is a test\nThis is only a test.”, 0, 0, 320, 0 , “Helvetica”, 16)

works but:

t = display.newText(“This is a test\nThis is only a test.”, 0, 0, “Helvetica”, 16)

does not.

Verified on my iPhone 5.

Used your library Satheesh, thank you very much!

What version of Corona SDK are you using?

Daily Build 1025

Off Topic :
 I wrote a multi-line library some time back which allows for center aligning each line of the multi-line text…
Give it a try if interested  :slight_smile:

http://developer.coronalabs.com/code/useful-multiline-text-library

Thank you Satheesh sounds interesting, will give it a try if Corona stuff confirms the “\n” is not working.

Can anyone confirm if the “\n” is working or not on the iPhone ?

You have to tell display.newText that you want multi line text:

t = display.newText(“This is a test\nThis is only a test.”, 0, 0, 320, 0 , “Helvetica”, 16)

works but:

t = display.newText(“This is a test\nThis is only a test.”, 0, 0, “Helvetica”, 16)

does not.

Verified on my iPhone 5.

Used your library Satheesh, thank you very much!

Rob’s solution of specifying the extra coordinates (320,0) solves this problem for me. But I did want to add just a little as an FYI. The \n without the extra coordinates works on Windows simulator but not on Mac simulator. It also works on Android devices but not iOS devices. I will further test to prove to myself that the new solution works on all platforms. Thanks, Rob, for the many working solutions you provide throughout the forums!

Rob’s solution of specifying the extra coordinates (320,0) solves this problem for me. But I did want to add just a little as an FYI. The \n without the extra coordinates works on Windows simulator but not on Mac simulator. It also works on Android devices but not iOS devices. I will further test to prove to myself that the new solution works on all platforms. Thanks, Rob, for the many working solutions you provide throughout the forums!

I can confirm what @PhilB1 has seen. Creating multiline text without width and height values will still properly display multiline text on the Windows corona simulator as well as Android devices, but will NOT on the MAC corona simulator and iOS devices.

Is there a reason why this won’t work on iOS but it does on Android? It can be very useful to specify a multiline text without a width. For instance, I let the user overlay text onto photos and I would like the width of the text to be exactly how long the text actually is. It is impossible to know what the width of the text will be before creating it.

On Android, corona just “does the right thing” and sets the width to the longest line of a multiline text. You can still properly set the align as well and everything just works. However, iOS was not so lucky.

Again, how come this works great on Android but not iOS?

I can confirm what @PhilB1 has seen. Creating multiline text without width and height values will still properly display multiline text on the Windows corona simulator as well as Android devices, but will NOT on the MAC corona simulator and iOS devices.

Is there a reason why this won’t work on iOS but it does on Android? It can be very useful to specify a multiline text without a width. For instance, I let the user overlay text onto photos and I would like the width of the text to be exactly how long the text actually is. It is impossible to know what the width of the text will be before creating it.

On Android, corona just “does the right thing” and sets the width to the longest line of a multiline text. You can still properly set the align as well and everything just works. However, iOS was not so lucky.

Again, how come this works great on Android but not iOS?