OverviewUILabel is a
Widget that can be used to display text.
All labels require a
Font to work with. This font can be
Dynamic (directly referencing a Unity Font), or it can be a
Bitmap font -- a font embedded within an Atlas. Dynamic fonts are more robust as they don't require you to pre-generate your glyphs before hand, but Bitmap fonts can be drawn within the same draw call as the rest of your atlas, and can be decorated nicely in an image editing tool such as Photoshop.
You can change the
alignment of the labels simply by switching the Pivot point. Top-left, Left and Bottom-left pivot point will result in a left-aligned text. Top, Center, or Bottom alignment will cause the text to be centered, and Top-right, Right or Bottom-right pivot will make your text right-aligned.
With the Dynamic font chosen you can set the
Font Size as well as style directly on your label. You can also set the material that will be used to draw it, if you wish.
The big box is -- as you probably guessed -- where you enter text. It's a multi-line text box by default, unless limited by the
Max Lines property below it.
Overflow handling lets you determine what happens when the label's text exceeds the allowed space.
- Shrink Content means the content will be automatically shrunk to best fit the area. It works in conjunction with the Keep Crisp setting if you are using a Dynamic font, making the font size shrink down, not just scaling the content. This results in crisp labels regardless of whether they were shrunk or not.
- Clamp Content simply means that if the text doesn't fit, it will be cut off.
- Resize Freely option will make the label's dimensions controlled by the text entered in the field. You won't be able to resize the dimensions yourself.
- The last option, Resize Height will add grow the height as necessary, but will keep the width constant.
The
Spacing field lets you adjust the distance between characters. Both positive and negative values are allowed. This value is in pixels.
Max Lines, as mentioned earlier, lets you control how many lines you want there to be at maximum. You can leave it at zero if you want it to be unlimited.
You can turn off
Encoding if you don't want color tags and emoticons to be processed. Input fields do this by default.
If you want, you can give your labels a
Gradient by specifying the bottom and top colors.
You can give your text a shadow or an outline
Effect, but note that doing so will double the geometry in case of shadow, and multiply it by a factor of 5 in case of outline -- so be mindful of this feature. The
Distance parameter controls how far the shadow or outline is from the base text, in pixels.
To change the label's text at run-time, you can do the following:
UILabel lbl = GetComponent<UILabel>();
lbl.text = "Hello world!";
Pro-Tip #1You can add bold, italic, underline, and other effects to your label by using bbcode syntax like so:
[b]bold[/b][i]italic[/i][u]underline[/u][s]strikethrough[/s]You can also embed clickable links in your labels like so:
[
url=Some Message or Link]Click Me[/url]
To retrieve what you clicked on, attach a box collider to your label (ALT+SHIFT+C) and a script that has a function like this in it:
void OnClick ()
{
UILabel lbl = GetComponent<UILabel>();
string url = lbl.GetUrlAtPosition(UICamera.lastWorldPosition);
Debug.Log("Clicked on: " + url);
}
Pro-Tip #2You can give your labels a
beveled look by specifying a dark foreground color and a bright Shadow effect.
Pro-Tip #3You can make the text ignore the label's color tint by using the
[c]text here[/c] tag, and change the alpha by using
[Aa] syntax, like "[7f]".
Class Documentationhttp://tasharen.com/ngui/docs/class_u_i_label.htmlIf you have a question regarding this component or would like me to clarify something, just post a reply here.