Author Topic: UILabel.Wrap fails with text containing '\n' characters  (Read 1631 times)

artefacts

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
UILabel.Wrap fails with text containing '\n' characters
« on: May 13, 2014, 10:19:44 AM »
Hi everyone,

I need to display a text in an UI Label. This text is dynamic (change during the game) and may contain '\n' characters.
The label has a maximum number of lines and I want to resize it on its width, not its height. I didn't find a way to do that using the parameters in the UILabel component so I decided to implement it myself.

For that, I use UILabel.Wrap(string, out string, int) method. The method returns true if the text given fits in the label, false otherwise.
But when my text contains a '\n' character, it returns true, even if the text does not fit.

I think the problem comes from the line : if (lineCount == maxLineCount) break;
The version of NGUI is 3.5.7.

I didn't find a bug tracker so I posted this here.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel.Wrap fails with text containing '\n' characters
« Reply #1 on: May 14, 2014, 05:20:10 AM »
Set the max line count to something higher (or just set it to 0 so it's not used). You can always count the number of newline characters after calling the Wrap function, and do any further formatting / trimming of the returned string.