Support => NGUI 3 Support => Topic started by: Baroni on July 17, 2013, 05:39:53 PM
Title: [SOLVED]UI Label line break \n \\n
Post by: Baroni on July 17, 2013, 05:39:53 PM
Hi,
straight to the point: The typical line break on UI Labels doesn't work. I attached a screenshot of one of your examples named "Example X", running Unity version 3.5.5f2 or 4.1.5f1 and NGUI 2.6.3.
You can see the line break approach with \n in the image, however I searched on the forums and found that one should use \\n now, but that doesn't work either. Encoding checked or unchecked, same result. Please advice me how to proceed further, thanks.
Title: Re: UI Label line break \n \\n, possible bug
Post by: dlewis on July 17, 2013, 11:48:42 PM
If you are entering text into the inspector then just hit the enter key. When you add text through code then it will turn \n into a new line.
Title: Re: UI Label line break \n \\n, possible bug
Post by: Baroni on July 18, 2013, 03:36:52 AM
Thanks for the reply, you're right. Just tested a direct assignment and it works as expected.
The real issue, however, lies in the (indirect) assignment of an inspector string to the UILabel via code. I can't do something like this:
public UILabel myUILabel;
publicstring myText;
void Start ()
{
myUILabel.text= myText;
}
With a \n or \\n , the UILabel will draw the text just as it is. I can't press enter in the inspector for a string value. Just to clarify: The \n version for strings gets displayed correctly in the free version of NGUI.
Title: Re: UI Label line break \n \\n, possible bug
Post by: ArenMook on July 18, 2013, 04:02:13 AM
So change your script:
public UILabel myUILabel;
publicstring myText;
void Start ()
{
myUILabel.text= myText.Replace("\\n", "\n");
}
The idea is that we don't want there to be a string.replace operation every time a string is assigned. It's slow and expensive and in most cases -- completely not necessary.
Title: Re: UI Label line break \n \\n, possible bug
Post by: Baroni on July 18, 2013, 04:21:27 AM