블로그 이미지
Every unexpected event is a path to learning for you. blueasa

카테고리

분류 전체보기 (2797)
Unity3D (853)
Programming (479)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (185)
협업 (61)
3DS Max (3)
Game (12)
Utility (68)
Etc (98)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (55)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday

NGUI UILabel Reference

Unity3D/NGUI / 2014. 12. 31. 14:40

Overview

UILabel 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:

Code: [Select]
UILabel lbl = GetComponent<UILabel>();
lbl.text = "Hello world!";


Pro-Tip #1

You 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:

Code: [Select]
void OnClick ()
{
    UILabel lbl = GetComponent<UILabel>();
    string url = lbl.GetUrlAtPosition(UICamera.lastWorldPosition);
    Debug.Log("Clicked on: " + url);
}


Pro-Tip #2

You can give your labels a beveled look by specifying a dark foreground color and a bright Shadow effect.



Pro-Tip #3

You 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 Documentation

http://tasharen.com/ngui/docs/class_u_i_label.html


출처 : http://www.tasharen.com/forum/index.php?topic=6706.0

반응형

'Unity3D > NGUI' 카테고리의 다른 글

NGUI UILabel로 Emoticon 넣기..  (0) 2015.02.12
Coloring individual characters in an NGUI UILabel text  (0) 2014.12.31
NGUI UILabel BBCode  (0) 2014.12.31
PSD Layers to PNG Files(PSD2PNGs)  (0) 2014.12.31
PSD Layers to 2D Tool Kit(PSD2TK2D)  (0) 2014.12.31
Posted by blueasa
, |