主题
EUIRichTextLabel
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUIRichTextLabel](30 属性)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
继承成员
2 个来源 / 38 属性 / 33 函数 / 10 事件
- 来自 EUINodeBase(34 属性 / 8 函数 / 4 事件)
- 属性:
Visible、Position、Anchor、FlippedX、FlippedY、Size、Rotation、Opacity、TouchBeginAudio、TouchEndAudio、TouchClickAudio、TouchbeginEvent、ClickEvent、TouchendEvent、LongtouchEvent、ShowEvent、HideEvent、TouchEnabled、SwallowTouchEnabled、TopAdaptMode、TopAdaption、BottomAdaptMode、BottomAdaption、LeftAdaptMode、LeftAdaption、RightAdaptMode、RightAdaption、AnchorXAdaptMode、AnchorXAdaption、AnchorYAdaptMode、AnchorYAdaption、LocalZOrder、LayoutOrder、Scale - 函数:
RemoveFromParent、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release - 事件:
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、GetFullPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUIRichTextLabel 是富文本标签控件,用于在界面中展示带样式的文本内容。它支持设置字体、颜色、描边、阴影、斜体等外观属性,并提供自动缩小字号、换行限制、溢出滚动等高级排版功能。
适用场景
当需要在玩家界面上显示一段可配置样式的文本时,例如聊天消息、提示信息或动态内容展示,可使用 EUIRichTextLabel 创建富文本标签。
使用要点
通过 World:CreateUnit 创建实例,并将 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()。然后直接读写 Text、TextColor、FontSize 等属性来配置文本样式,或设置 WrapWidth、AutoSizeEnabled 等属性控制排版行为。
注意事项
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 | 富文本标签显示的文本内容。 |
TextColor | Color | [255, 255, 255, 255] | 富文本标签的文本颜色。 |
FontSize | Int | 42 | 文本的字体大小。 |
Font | TextFontType | Enums.TextFontType.HKXZYT_W9_GB | 文本使用的字体。 |
OutlineEnabled | Bool | false | 是否启用文本描边效果。 |
OutlineColor | Color | [0, 0, 0, 0] | 富文本标签的描边颜色。 |
OutlineWidth | Int | 1 | 文本描边的宽度。 |
OutlineOpacity | Float | 1.0 | 文本描边的透明度。 |
ShadowEnabled | Bool | false | 是否启用文本阴影效果。 |
ShadowColor | Color | [0, 0, 0, 0] | 富文本标签的阴影颜色。 |
ShadowOffset | Vector2 | [1, 1] | 富文本标签的阴影偏移量。 |
ItalicEnabled | Bool | false | 是否启用斜体样式。 |
TextHorizontalAlignment | Int | 0 (Left) | 文本的水平对齐方式。 |
TextVerticalAlignment | Int | 0 (Top) | 文本的垂直对齐方式。 |
WrapWidth | Int | - | 文本换行的宽度。 |
SingleLineMinWidth | Int | - | 单行文本的最小宽度。 |
SingleLineMaxWidth | Int | - | 单行文本的最大宽度。 |
WrapMaxHeight | Int | - | 文本换行区域的最大高度。 |
WrapMinHeight | Int | - | 文本换行区域的最小高度。 |
AutoSizeEnabled | Bool | false | 是否启用自动缩小字号以适应标签尺寸。 |
MinFontSize | Int | 12 | 自动缩放字号时的最小允许字号。 |
TextSpacing | Int | 0 | 字符之间的间距。 |
LineSpacing | Int | - | 文本行与行之间的间距。 |
EnableMaxHeight | Bool | false | 是否启用最大高度限制。 |
ShrinkFontSizeStep | Float | 1.0 | 自动缩小字号时的步长。 |
OverflowPolicy | Int | 1 (Culling) | 文本溢出时的处理策略。 |
AutoScrollSpeed | Float | 100.0 | 自动滚动的速度。 |
AutoScrollProgress | Float | 0.0 | 自动滚动时的循环间距。 |
ArrangeMode | Int | 2 (AutoWrap) | 文本的排列模式。 |
EnableMaxWidth | Bool | false | 是否启用最大宽度限制。 |
