主题
EUITextLabel
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUITextLabel](14 属性)
- 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
- 属性:
EUITextLabel 是用于在界面上显示文本的控件,支持设置文本内容、字体、大小、颜色以及描边和阴影等样式。通过调整对齐方式与斜体等属性,可以灵活控制文本在标签区域内的呈现效果。
适用场景
常用于在玩家界面上创建标题、提示信息或数值显示,例如在屏幕顶部显示得分或在按钮上添加文字说明。
使用要点
通过 World:CreateUnit("EUITextLabel", config) 创建实例,并将 Parent 设置为 PlayerGui.EuiManager:GetRootNode() 以挂载到界面。然后直接对实例的 Text、FontSize、TextColor 等属性赋值来更新显示内容与样式。
注意事项
EUITextLabel 是文本标签控件,通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()。文本与样式通过公开属性在 CreateUnit config 中初始化或赋值更新,不要调用 publish=false 的 Set 系列方法。Color 使用 0-255 RGBA 四参数构造。
代码示例
创建文本标签并设置样式
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 label = World:CreateUnit("EUITextLabel", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
Text = "任务已完成",
FontSize = 28,
TextColor = Color.New(255, 240, 120, 255),
})属性 (14)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Text | String | "" | 显示的文本内容。 |
TextColor | Color | [255, 255, 255, 255] | 文本内容的颜色,使用 Color 类型表示 RGBA 值。 |
FontSize | Int | 42 | 文本的字体大小。 |
Font | TextFontType | Enums.TextFontType.HKXZYT_W9_GB | 文本的字体。 |
OutlineEnabled | Bool | false | 是否启用文本描边。 |
OutlineColor | Color | [0, 0, 0, 0] | 文本描边的颜色,使用 Color 类型表示 RGBA 值。 |
OutlineWidth | Int | 1 | 文本描边的宽度。 |
OutlineOpacity | Float | 1.0 | 文本描边的透明度。 |
ShadowEnabled | Bool | false | 是否启用文本阴影。 |
ShadowColor | Color | [0, 0, 0, 0] | 文本阴影的颜色,使用 Color 类型表示 RGBA 值。 |
ShadowOffset | Vector2 | [1, 1] | 文本阴影相对于文本的偏移量,使用 Vector2 类型表示水平和垂直方向的偏移。 |
ItalicEnabled | Bool | false | 是否启用斜体样式。 |
TextHorizontalAlignment | Int | 0 (Left) | 文本的水平对齐方式。 |
TextVerticalAlignment | Int | 0 (Top) | 文本的垂直对齐方式。 |
