# UILabel
# 概述
UILabel 是基础的文本组件。
# 属性
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| text | string | "" | 文本内容,"\n" 表示换行 |
| italic | boolean | false | 是否为斜体 |
| bold | boolean | false | 是否为粗体 |
| fontFamily | string | "Arial" | 字体名 |
| font | Font | null | 自定义字体资源,设置字体资源以后 fontFamily 属性也会被同步设置 |
| bitmapFont | BitmapFont | null | 位图字体资源 |
| fontSize | number | 12 | 文字大小,单位px |
| fontColor | Color | new Color(0, 0, 0, 255) | 字体颜色 |
| applyGradient | boolean | false | 是否使用渐变色 |
| gradientTop | Color | new Color(0, 0, 0, 255) | 是否使用渐变色 |
| gradientBottom | Color | new Color(0, 0, 0, 255) | 是否使用渐变色 |
| spacing | number | 0 | 字间距,单位 px |
| lineSpace | number | 0 | 行间距,单位 px |
| align | enum | 1 | 水平对齐方式,1 左对齐,2 居中对齐,3 右对齐 |
| valign | enum | 1 | 垂直对齐方式,1 顶部对齐,2 居中对齐,3 底部对齐 |
| wordWrap | boolean | false | 是否根据 entity.transform2D.size.x 自动换行 |
| autoSize | boolean | false | 是否根据 UILabel 的渲染大小自动设置 entity.transform2D.size |
| stroke | number | 0 | 描边宽度 |
| strokeColor | Color | new Color(0, 0, 0, 255) | 描边颜色 |
| underline | number | 0 | 下划线宽度 |
| underlineColor | Color | new Color(0, 0, 0, 255) | 下划线颜色 |
| shadowOffset | Vector2 | (0,0) | 阴影偏移量 |
| shadowColor | Color | new Color(0, 0, 0, 255) | 阴影颜色 |
| emoji | boolean | false | 文本中是否有 emoji 字符。渲染 emoji 是一个更加耗时的过程,应在必要时才设置该属性。 |
# 使用方法
UILabel 是渲染组件,因此需要挂载到非渲染节点上。
const entity = engine.Entity.createEntity2D("UILabel");
const label = entity.addComponent(engine.UILabel);
label.text = "12345";
label.fontSize = 40;
label.fontColor = new engine.Color(0, 255, 0, 255);
label.align = 1;
label.valign = 2;
label.underline = 10;
label.bold = true;
label.applyGradient = true;
label.gradientTop = new engine.Color(255, 0, 0, 255);
label.gradientBottom = new engine.Color(0, 0, 255, 255);
label.autoSize = true;
label.shadowColor = new engine.Color(255, 255, 255, 255);
label.shadowOffset = new engine.Vector2.createFromNumber(4, 4);