NGUI Label Color Code

时间:2023-11-24 21:54:08

UILabel的颜色代码

NGUI的Label文档:http://www.tasharen.com/?page_id=166

you can embed colors in [RrGgBb] format. For example, red color is [FF0000], green is [00FF00], etc. You can also use [-] to revert to a previous color. For example, the following text: “Hello [FF0000]World[-]!” will result in: Hello World!

就是说如果单个字体要变色需要使用十六进制的颜色代码,当然如果你是修改整个Label的颜色就不需要这么麻烦了。

我的处理方法

下面说一下我的处理方式:

1、先把颜色定义写在一个常量类中

public class GameDef
{
//NGUI Label 上的文字颜色 十六进制代码
public const string NguiLbl_Color_Red = "[FF0000]";
public const string NguiLbl_Color_Green = "[00FF00]";
public const string NguiLbl_Color_Blue = "[0000FF]";
public const string NguiLbl_Color_White = "[FFFFFF]";
public const string NguiLbl_Color_Glod = "[FFD700]";
} //使用方法
Message =string.Format("武器库超出了 {0}{1}[-] 件",GameDef.NguiLbl_Color_Red,overNum),

2、在用的地方拼字符串。

所谓的RrGgBb 格式是这样的

RR   :    红色值。十六进制正整数
GG  :   绿色值。十六进制正整数

BB   :    蓝色值。十六进制正整数

以上三个参数,取值范围为:00 - FF。

参数必须是两位数。对于只有一位的,应在前面补零。

如果每个参数各自在两位上的数字都相同,那么本单位也可缩写为#RGB的方式。例如:#FF8800 可以缩写为 #F80。

关于十六进制颜色的更多信息,可以参考下面两个网站:

W3C - 十六色色盘

http://www.goodxyx.com/css/chm/z_color.html

NGUI Label Color Code

HTML Color Codes

http://www.rapidtables.com/web/color/html-color-codes.htm

NGUI Label Color Code