主题
EUISimpleRichTextLabel
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
- [EUISimpleRichTextLabel](20 属性)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
继承成员
2 个来源 / 39 属性 / 36 函数 / 10 事件
- 来自 EUINodeBase(35 属性 / 12 函数 / 4 事件)
- 属性:
Visible、Position、Anchor、FlippedX、FlippedY、Size、Rotation、Opacity、TouchBeginAudio、TouchEndAudio、TouchClickAudio、TouchbeginEvent、ClickEvent、TouchendEvent、LongtouchEvent、ShowEvent、HideEvent、TouchEnabled、TouchDragEnabled、SwallowTouchEnabled、TopAdaptMode、TopAdaption、BottomAdaptMode、BottomAdaption、LeftAdaptMode、LeftAdaption、RightAdaptMode、RightAdaption、AnchorXAdaptMode、AnchorXAdaption、AnchorYAdaptMode、AnchorYAdaption、LocalZOrder、LayoutOrder、Scale - 函数:
RemoveFromParent、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release、GetWorldPosition、ConvertToWorldPosition、ConvertToLocalPosition、HitTest - 事件:
OnTouchBegan、OnTouchMoved、OnTouchEnded、OnClicked
- 属性:
- 来自 Unit(4 属性 / 25 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUISimpleRichTextLabel 是用于界面文字展示的 UI 单位,可在同一段文本上统一控制字体、字号、颜色、描边、阴影与斜体等外观效果,并提供水平对齐、垂直对齐、字间距与行间距等排版能力。当文本超出控件范围时,它还能通过超框策略与爆框策略决定裁剪、换行或滚动方式,并可开启自动缩小字号配合最小字号限制来适配有限空间。
适用场景
适合在界面根节点下创建公告、活动说明或任务提示这类长度可变且需要统一排版效果的文本控件,例如在 EuiManager 返回的根节点上创建标签并写入提示文案。
使用要点
先通过 game:GetService("Players").LocalPlayer.PlayerGui.EuiManager:GetRootNode() 取得界面根节点,再调用 game:GetService("World"):CreateUnit("EUISimpleRichTextLabel", { Parent = 根节点, Position = Vector2.New(0, 0), Size = Vector2.New(100, 40) }) 创建实例。创建完成后写入 Text,并配合 TextColor、Font、FontSize、OutlineEnabled、OutlineColor、OutlineWidth、OutlineOpacity、ShadowEnabled、ShadowColor、ShadowOffset、ItalicEnabled 调整外观,再用 TextHorizontalAlignment、TextVerticalAlignment、TextSpacing、LineSpacing 完成排版。
注意事项
该单位不能自行构造,只能通过 World:CreateUnit 创建并挂载到界面节点下,创建时需同时给出 Parent、Position 与 Size,否则控件可能无法正常显示。文本超框行为由 OverflowStrategy 与 ResetSizePolicy 控制,取值形如 Enums.EUIOverflowStrategy.Ellipsis 与 Enums.EUIResetSizePolicy.FitWidth;启用 AutoSizeEnabled 时应一并设置 MinFontSize 以限定最小可用字号。
代码示例
创建 EUISimpleRichTextLabel 实例
lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService('World')
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local eUISimpleRichTextLabel = World:CreateUnit("EUISimpleRichTextLabel", { Parent = rootNode })
if eUISimpleRichTextLabel == nil then return end
print('EUISimpleRichTextLabel 已创建:', eUISimpleRichTextLabel.Name)属性 (20)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Text | String | SimpleRichText | EUISimpleRichTextLabel 显示的文本内容,类型为 String,该标签以简单富文本形式呈现这段文字。 |
TextColor | Color | [255, 255, 255, 255] | EUISimpleRichTextLabel 的文字主体颜色,类型为 Color,包含红、绿、蓝与透明度分量。 |
FontSize | Int | 42 | EUISimpleRichTextLabel 的文字字号,类型为 Int,决定标签渲染正文的基础大小。 |
Font | TextFontType | Enums.TextFontType.HKXZYT_W9_GB | EUISimpleRichTextLabel 的文字字体,类型为 TextFontType,用于指定标签内文字使用的字形族。它与 FontSize、MinFontSize 等字号类属性共同决定文字外观。 |
OutlineEnabled | Bool | false | EUISimpleRichTextLabel 的描边开关,类型为 Bool,用于决定是否为文字绘制描边。 |
OutlineColor | Color | [0, 0, 0, 0] | EUISimpleRichTextLabel 的文字描边颜色,类型为 Color,包含红、绿、蓝与透明度分量。 |
OutlineWidth | Int | 1 | EUISimpleRichTextLabel 的描边宽度,类型为 Int,用于控制文字轮廓的粗细。 |
OutlineOpacity | Float | 1.0 | EUISimpleRichTextLabel 描边的不透明度,类型为 Float,用于单独调节描边的透明程度。 |
ShadowEnabled | Bool | false | EUISimpleRichTextLabel 的阴影开关,类型为 Bool,用于决定是否为文字绘制阴影。 |
ShadowColor | Color | [0, 0, 0, 0] | EUISimpleRichTextLabel 的文字阴影颜色,类型为 Color,包含透明度分量。 |
ShadowOffset | Vector2 | [1, 1] | EUISimpleRichTextLabel 的阴影偏移属性,类型为 Vector2,用来表示该富文本标签的阴影相对文字本体在水平与垂直两个方向上的偏移量。类型清单中标注其默认值为 (1, 1),即阴影默认沿 x、y 方向各偏移一个单位。该属性只描述阴影的位置偏移,本身不控制阴影是否显示,也不控制阴影颜色。 |
ItalicEnabled | Bool | false | EUISimpleRichTextLabel 是否使用斜体,类型为 Bool。 |
TextHorizontalAlignment | EUITextHorizontalAlignment | Enums.EUITextHorizontalAlignment.Left | EUISimpleRichTextLabel 文字在标签内的水平对齐方式,类型为 EUITextHorizontalAlignment。 |
TextVerticalAlignment | EUITextVerticalAlignment | Enums.EUITextVerticalAlignment.Top | EUISimpleRichTextLabel 文字在标签内的垂直对齐方式,类型为 EUITextVerticalAlignment。 |
TextSpacing | Int | 0 | EUISimpleRichTextLabel 文字中字符之间的间距,类型为 Int。 |
LineSpacing | Int | - | EUISimpleRichTextLabel 多行文本的行间距,类型为 Int。 |
AutoSizeEnabled | Bool | false | EUISimpleRichTextLabel 是否启用字号自动缩小,类型为 Bool,用于让文字在可用区域内自适应。 |
MinFontSize | Int | 12 | EUISimpleRichTextLabel 在自动缩小时允许的最小字号,类型为 Int。 |
OverflowStrategy | EUIOverflowStrategy | Enums.EUIOverflowStrategy.AutoScroll | EUISimpleRichTextLabel 在文本超出标签区域时采用的超框策略,类型为 EUIOverflowStrategy。 |
ResetSizePolicy | EUIResetSizePolicy | Enums.EUIResetSizePolicy.AutoScroll | EUISimpleRichTextLabel 的尺寸重置策略,类型为 EUIResetSizePolicy,用于指定文本尺寸的自适应方式。 |
