主题
EUIRichTextLabel
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(5 属性 / 28 函数 / 6 事件)
- EUINodeBase(35 属性 / 13 函数 / 4 事件)
- [EUIRichTextLabel](31 属性)
- EUINodeBase(35 属性 / 13 函数 / 4 事件)
继承成员
2 个来源 / 40 属性 / 39 函数 / 10 事件
- 来自 EUINodeBase(35 属性 / 13 函数 / 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、Clone、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release、GetWorldPosition、ConvertToWorldPosition、ConvertToLocalPosition、HitTest - 事件:
OnTouchBegan、OnTouchMoved、OnTouchEnded、OnClicked
- 属性:
- 来自 Unit(5 属性 / 28 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent、Tags - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetDebugId、HasTag、AddTag、RemoveTag - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
富文本标签控件用于在界面根节点下呈现可精细排版的文本内容,支持字体、字号、描边、阴影、斜体以及水平与垂直对齐等样式设置。它提供换行宽度、最大与最小高度、字间距和行间距等排版控制,并可通过自动缩小字号与溢出策略处理超长文本。结合自动滚动速度和排列模式,还能兼顾单行展示与自动换行两种形态。
适用场景
适用于公告栏、剧情字幕、战斗提示等需要描边、阴影和自动换行排版的文本展示场景。在界面根节点下创建标签并设置文本与样式,即可完成常见的信息呈现。
使用要点
先通过 game:GetService 获取 Players 与 World 服务,并使用 Players.LocalPlayer.PlayerGui.EuiManager:GetRootNode() 取得界面根节点。随后调用 World:CreateUnit 创建 EUIRichTextLabel,并把 Parent 指向该根节点。创建完成后设置 Text、TextColor、FontSize、Font 与对齐属性完成基础排版,长文本可结合 WrapWidth、WrapMaxHeight、OverflowPolicy 控制换行与溢出;需要自适应时开启 AutoSizeEnabled 并设置 MinFontSize、ShrinkFontSizeStep。
注意事项
EUIRichTextLabel 是富文本标签控件,通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()(不能自行直接构造,也不能通过 GetService 获取 EUIManager)。Color 类型必须用 0-255 RGBA 四参数构造(如 Color.New(255, 0, 0, 255)),不能用 0-1 归一化值。
代码示例
创建富文本标签并设置排版样式
lua
-- @runtime client
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local World = game:GetService("World")
local label = World:CreateUnit("EUIRichTextLabel", {
Parent = rootNode,
Position = Vector2.New(160, 80),
Size = Vector2.New(300, 100),
Text = "任务奖励:金币 x100",
FontSize = 24,
TextColor = Color.New(255, 230, 120, 255),
OutlineEnabled = true,
OutlineColor = Color.New(0, 0, 0, 255),
WrapWidth = 280,
})属性 (31)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
AutomaticSize | Int | 0 | 内容自动尺寸属性,用于描述 EUIRichTextLabel 节点在尺寸计算上的自动尺寸设定,数据类型为整数(Int)。该属性属于 EUIRichTextLabel 的公开属性,可通过节点实例读取当前值,也可以为其赋新的整数值。 |
Text | String | RichTextLabel | 富文本标签展示的文本内容,类型为 String,赋值后即成为该标签当前显示的文本。 |
TextColor | Color | [255, 255, 255, 255] | 文本主体颜色,类型为 Color,包含红、绿、蓝与透明度分量。 |
FontSize | Int | 42 | 文本的字号大小,类型为 Int。 |
Font | TextFontType | Enums.TextFontType.HKXZYT_W9_GB | 文本所使用的字体,取值类型为 TextFontType,用于决定文字的字形样式。 |
OutlineEnabled | Bool | false | 是否开启文本描边效果,类型为 Bool。 |
OutlineColor | Color | [0, 0, 0, 0] | 文本描边的颜色,类型为 Color,包含红、绿、蓝与透明度分量。 |
OutlineWidth | Int | 1 | 文本描边的宽度,类型为 Int。 |
OutlineOpacity | Float | 1.0 | 文本描边的不透明度,类型为 Float。 |
ShadowEnabled | Bool | false | 是否开启文字阴影,类型为 Bool。 |
ShadowColor | Color | [0, 0, 0, 0] | 文字阴影的颜色,类型为 Color。 |
ShadowOffset | Vector2 | [1, 1] | 文本阴影的偏移量,类型为 Vector2,默认值为 (1, 1)。该属性描述 EUIRichTextLabel 上文字阴影相对文字本体的位移,由横纵两个分量共同决定。它与同属阴影配置的 ShadowEnabled、ShadowColor 一起构成富文本标签的阴影样式。 |
ItalicEnabled | Bool | false | 是否以斜体样式渲染文本,类型为 Bool。 |
TextHorizontalAlignment | EUITextHorizontalAlignment | Enums.EUITextHorizontalAlignment.Left | 文本在标签范围内的水平对齐方式,取值类型为 EUITextHorizontalAlignment。 |
TextVerticalAlignment | EUITextVerticalAlignment | Enums.EUITextVerticalAlignment.Top | 文本在标签范围内的垂直对齐方式,取值类型为 EUITextVerticalAlignment。 |
WrapWidth | Int | - | 文本自动换行时使用的宽度阈值,类型为 Int。 |
SingleLineMinWidth | Int | - | 单行文本的宽度下限,类型为 Int。 |
SingleLineMaxWidth | Int | - | 单行文本的宽度上限,类型为 Int。 |
WrapMaxHeight | Int | - | 换行排版时文本允许占用的最大高度,类型为 Int。 |
WrapMinHeight | Int | - | 换行排版时文本至少占用的高度,类型为 Int。 |
AutoSizeEnabled | Bool | false | 是否在文本超出可用空间时自动缩小字号,类型为 Bool。 |
MinFontSize | Int | 12 | 自动缩小字号时可达到的最小字号,类型为 Int。 |
TextSpacing | Int | 0 | 字符之间的间距,类型为 Int。 |
LineSpacing | Int | - | 多行文本之间的行间距,类型为 Int。 |
EnableMaxHeight | Bool | false | 是否启用最大高度限制,类型为 Bool。 |
ShrinkFontSizeStep | Float | 1.0 | 自动缩小字号时每次缩小的步长,类型为 Float。 |
OverflowPolicy | EUIOverflowPolicy | Enums.EUIOverflowPolicy.Culling | 文本内容超出显示范围时的处理策略,取值类型为 EUIOverflowPolicy。 |
AutoScrollSpeed | Float | 100.0 | 自动滚动时的滚动速度,类型为 Float。 |
AutoScrollProgress | Float | 0.0 | 自动滚动时的循环间距,类型为 Float,用于控制滚动内容首尾衔接的间隔。 |
ArrangeMode | EUIArrangeMode | Enums.EUIArrangeMode.AutoWrap | 文本的排列模式,取值类型为 EUIArrangeMode。 |
EnableMaxWidth | Bool | false | 是否启用最大宽度限制,类型为 Bool。 |
