Author Topic: UILabel  (Read 112357 times)

sstublic

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 15
    • View Profile
Re: UILabel
« Reply #120 on: December 15, 2014, 12:03:08 PM »
Hi!

I have the following problem: I'm using UILabel to display text (which is dynamic, meaning I don't know exact contents at compile time) which is in blue gradient.
However, some of the words in the text need to be able to become orange gradient (as in highlighted).

Basically I could do this by making the gradient light gray to dark gray and then use UILabel color (via color escape codes) to tint that gradient either blue or orange.
HOWEVER, this solution doesn't work for me, because color gradients I'm using CANNOT be reproduced as a combination of gray gradient and tint.

Could you point me in any meaningful direction how to do this either by:
a) extending color coding functionality to allow gradient escape codes (as in for example [RrGgBb, RrGgBb])
b) somehow preprocessing the text myself before hand and then programatically generate 'concatenated' multiple labels, each for the same colored segment

I've been looking at UILabel code and NGUIText code, but I'd like a way to this without modifying your code, or at least without modifying a lot of it.

Could something like this be done via UILabel inheritance? Do you have any other ideas how to do this?

Thanks!


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UILabel
« Reply #121 on: December 30, 2014, 01:57:36 PM »
Preprocessing is trivial. When you are about to set the label's text, do your parsing that will determine which gradient should be used and set the label's gradientTop and gradientBottom accordingly. There is no need to modify NGUI for this.

sstublic

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 15
    • View Profile
Re: UILabel
« Reply #122 on: January 17, 2015, 06:30:12 AM »
Since I needed some of the words having different gradient in the same label (as explained above), that approach wouldn't work at all.

I ended up modifying NGUIText.cs and inserting it to call custom function whenever it's determining final color for each letter using its tint and gradient (in my case either top or bottom). Something like:

  1.  public static Color CombineTintAndGradient(Color tint, Color gradient)

This allowed me to write custom logic on how gradients are formed and fixed my problem. It is a hack, but worked.
If anyone runs into similar problems, feel free to msg me for details.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UILabel
« Reply #123 on: February 13, 2015, 09:27:40 AM »
I would love to have a bbcode-like tag like so:

  1. label.text = "I'm a text with [size=+10] big parts[/size] and [size=-10] small parts[/size] and a [size=14]absolute sized part[/size]"
  2.  

To generate a single label with multiple sizes

I'm a text with big parts and small parts and an absolute sized part.

Since designers tend to want that and right now I have to create multiple UILabels and align them and all sorts of shenanigans to fill out each individual label with data.

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: UILabel
« Reply #124 on: March 17, 2015, 07:00:00 AM »
I would love to have a bbcode-like tag like so:

  1. label.text = "I'm a text with [size=+10] big parts[/size] and [size=-10] small parts[/size] and a [size=14]absolute sized part[/size]"
  2.  

To generate a single label with multiple sizes

I'm a text with big parts and small parts and an absolute sized part.

Since designers tend to want that and right now I have to create multiple UILabels and align them and all sorts of shenanigans to fill out each individual label with data.

I second this. Designers sure can get sad when you deny them this... :)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UILabel
« Reply #125 on: March 19, 2015, 05:11:15 PM »
I've actually made a version of this in the project I'm working on now, but it has some dodgy bits so I haven't been able to push it back to NGUI. The issue comes from how it calculates width and height - width can be solved because you can add each glyph one at a time like you do now, but figuring out the height of a line is difficult, because you have to parse through the whole line before you can reliably place the first character - that means you have to run through each line twice to place the vertical placement properly and that sorta sucks.

That said, as long as you work on a single line it can work. I do it with [size=0.5] where the size is relative to the label's default size. If I can find time to clean it up, I'll push this back to NGUI in a pull request.

I second this. Designers sure can get sad when you deny them this... :)

Tatanan

  • Jr. Member
  • **
  • Thank You
  • -Given: 11
  • -Receive: 0
  • Posts: 81
    • View Profile
    • Casual Arena
Re: UILabel
« Reply #126 on: April 15, 2015, 09:26:52 AM »
What's the difference between Outline and Outline8?
Game developer on Casual Arena.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UILabel
« Reply #127 on: April 16, 2015, 07:43:19 AM »
Outline draws the outline by drawing text 4 extra times. Outline8 draws it 8 extra times

Tatanan

  • Jr. Member
  • **
  • Thank You
  • -Given: 11
  • -Receive: 0
  • Posts: 81
    • View Profile
    • Casual Arena
Re: UILabel
« Reply #128 on: April 16, 2015, 07:52:54 AM »
I guess I should just use outline "4", right?
Game developer on Casual Arena.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UILabel
« Reply #129 on: April 16, 2015, 08:25:19 AM »
In most cases, yup.

dadrester

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UILabel
« Reply #130 on: July 30, 2015, 07:57:42 AM »
What are the chances of getting functionality for changing font within a label? (if it's within the same atlas). I'm assuming they're low :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UILabel
« Reply #131 on: July 31, 2015, 10:11:50 PM »
Yeah it complicates the label's code drastically. I personally don't want to delve into that as I know it will cause more harm (read: bugs) than good. With the ability to change colors, italic / bold / underline and have hyperlinks / emoticons in text, you can already customize it quite a bit. The ability to change fonts halfway through the sentence is a niche feature.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: UILabel
« Reply #132 on: December 30, 2015, 08:18:09 AM »
I've got a question about creating multiple line breaks through code, say if I wanted something like:
Some Text
[blank line]
More Text

The only way I've found to accomplish this is to do:
  1.         void SomeMethod()
  2.         {
  3.                 //show popup that lets the user know we are validating their internet connection:
  4.                 failureString = "Could not verify internet connection, make sure you have access to a network and are connected to it. Please wait 10 seconds after fixing your connection before trying again.@@(Tap to Clear)";
  5.                 failureString = failureString.Replace ("@", "\n");
  6.  
  7.                 //or could use: failureString = "Could not verify internet connection, make sure you have access to a network and are connected to it. Please wait 10 seconds after fixing your connection before trying again." + "\n" + "\n" + "(Tap to Clear)";
  8.  
  9.                 label.text = failureString;
  10.         }

Where the text for the string is added later in the script after the declaration of the string. Declaring the string with the text, then running Replace() doesn't work (and running Replace() on label.text also has issues), and everything else I've tried results in:
Some Text
More Text

Any ideas are appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UILabel
« Reply #133 on: January 01, 2016, 07:24:07 PM »
Why are you doing the replace at all? Just have "\n" there to begin with. It's always like that with text.
  1. failureString = "Could not verify internet connection, make sure you have access to a network and are connected to it. Please wait 10 seconds after fixing your connection before trying again.\n\n(Tap to Clear)";

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: UILabel
« Reply #134 on: January 02, 2016, 06:25:23 AM »
"Why are you doing the replace at all? Just have "\n" there to begin with. It's always like that with text."

I could swear I tried that (since as you say, this is a common behavior). But I did try it again and it worked, really don't know what I was doing wrong when I was trying this before but everything is fine now. Thank you for your time.