Skip to content

EUISimpleRichTextLabel ​

概览 ​

字段值
KindUnit · 单位 Unit
Realmcommon

继承关系 ​

  • Unit(4 属性 / 25 函数 / 6 事件)
    • EUINodeBase(35 属性 / 12 函数 / 4 事件)
      • [EUISimpleRichTextLabel](20 属性)

继承成员 ​

2 个来源 / 39 属性 / 36 函数 / 10 事件

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类型默认值说明
TextStringSimpleRichTextEUISimpleRichTextLabel 显示的文本内容,类型为 String,该标签以简单富文本形式呈现这段文字。
TextColorColor[255, 255, 255, 255]EUISimpleRichTextLabel 的文字主体颜色,类型为 Color,包含红、绿、蓝与透明度分量。
FontSizeInt42EUISimpleRichTextLabel 的文字字号,类型为 Int,决定标签渲染正文的基础大小。
FontTextFontTypeEnums.TextFontType.HKXZYT_W9_GBEUISimpleRichTextLabel 的文字字体,类型为 TextFontType,用于指定标签内文字使用的字形族。它与 FontSize、MinFontSize 等字号类属性共同决定文字外观。
OutlineEnabledBoolfalseEUISimpleRichTextLabel 的描边开关,类型为 Bool,用于决定是否为文字绘制描边。
OutlineColorColor[0, 0, 0, 0]EUISimpleRichTextLabel 的文字描边颜色,类型为 Color,包含红、绿、蓝与透明度分量。
OutlineWidthInt1EUISimpleRichTextLabel 的描边宽度,类型为 Int,用于控制文字轮廓的粗细。
OutlineOpacityFloat1.0EUISimpleRichTextLabel 描边的不透明度,类型为 Float,用于单独调节描边的透明程度。
ShadowEnabledBoolfalseEUISimpleRichTextLabel 的阴影开关,类型为 Bool,用于决定是否为文字绘制阴影。
ShadowColorColor[0, 0, 0, 0]EUISimpleRichTextLabel 的文字阴影颜色,类型为 Color,包含透明度分量。
ShadowOffsetVector2[1, 1]EUISimpleRichTextLabel 的阴影偏移属性,类型为 Vector2,用来表示该富文本标签的阴影相对文字本体在水平与垂直两个方向上的偏移量。类型清单中标注其默认值为 (1, 1),即阴影默认沿 x、y 方向各偏移一个单位。该属性只描述阴影的位置偏移,本身不控制阴影是否显示,也不控制阴影颜色。
ItalicEnabledBoolfalseEUISimpleRichTextLabel 是否使用斜体,类型为 Bool。
TextHorizontalAlignmentEUITextHorizontalAlignmentEnums.EUITextHorizontalAlignment.LeftEUISimpleRichTextLabel 文字在标签内的水平对齐方式,类型为 EUITextHorizontalAlignment。
TextVerticalAlignmentEUITextVerticalAlignmentEnums.EUITextVerticalAlignment.TopEUISimpleRichTextLabel 文字在标签内的垂直对齐方式,类型为 EUITextVerticalAlignment。
TextSpacingInt0EUISimpleRichTextLabel 文字中字符之间的间距,类型为 Int。
LineSpacingInt-EUISimpleRichTextLabel 多行文本的行间距,类型为 Int。
AutoSizeEnabledBoolfalseEUISimpleRichTextLabel 是否启用字号自动缩小,类型为 Bool,用于让文字在可用区域内自适应。
MinFontSizeInt12EUISimpleRichTextLabel 在自动缩小时允许的最小字号,类型为 Int。
OverflowStrategyEUIOverflowStrategyEnums.EUIOverflowStrategy.AutoScrollEUISimpleRichTextLabel 在文本超出标签区域时采用的超框策略,类型为 EUIOverflowStrategy。
ResetSizePolicyEUIResetSizePolicyEnums.EUIResetSizePolicy.AutoScrollEUISimpleRichTextLabel 的尺寸重置策略,类型为 EUIResetSizePolicy,用于指定文本尺寸的自适应方式。

关联类型 ​