主题
EUIRichTextLabel
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
- [EUIRichTextLabel](30 属性)
- 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
- 属性:
EUIRichTextLabel 是界面层的富文本标签控件,用于在界面根节点下呈现可换行、可自适应的文字内容。它通过 Text、FontSize、Font、TextColor 组合控制文字外观,并提供描边、阴影、斜体等装饰开关。面对长文本时,还可以用 WrapWidth、WrapMaxHeight、OverflowPolicy、AutoSizeEnabled 与 MinFontSize 等属性调整排版与溢出表现。
适用场景
适合制作公告栏、任务说明、道具描述或对话旁白等需要大段文字与精细排版的界面元素:先在界面根节点下创建该控件,再逐项写入 Text、TextColor、FontSize、WrapWidth、OverflowPolicy 等属性完成排版配置。
使用要点
先通过 game:GetService("Players") 取得 Players.LocalPlayer,并在其为空时提前返回;再用 game:GetService("World") 获取世界服务,从 localPlayer.PlayerGui.EuiManager:GetRootNode() 拿到界面根节点。随后调用 World:CreateUnit("EUIRichTextLabel", { Parent = rootNode }) 创建实例,并按需设置 Text、FontSize、Font 与 TextColor(颜色使用 Color.New(255, 0, 0, 255) 这类 0 到 255 的四通道取值)。接着可叠加 OutlineEnabled、OutlineColor、ShadowEnabled、ShadowOffset 等装饰属性,长文本场景再配合 OverflowPolicy(如 Enums.EUIOverflowPolicy.Culling)、ArrangeMode(如 Enums.EUIArrangeMode.AutoWrap)与 AutoSizeEnabled、MinFontSize 完成排版。
注意事项
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,
})属性 (30)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
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。 |
