学习
引擎类
TextButton

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处



API 参考
属性
ContentText
只读
未复制
读取并联
功能: UI
TextButton.ContentText:string

Font
隐藏
未复制
读取并联
功能: UI
TextButton.Font:Enum.Font
代码示例
显示所有字体
local frame = script.Parent
-- 创建一个显示每种字体的 TextLabel
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- 设置文本属性
textLabel.Text = font.Name
textLabel.Font = font
-- 一些渲染属性
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- 将框架的大小设为文本的高度
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- 添加到父框架
textLabel.Parent = frame
end
-- 将框架按列表布局(如果它们还没有)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end

FontFace
读取并联
功能: UI
TextButton.FontFace:Font

FontSize
已弃用

LineHeight
读取并联
功能: UI
TextButton.LineHeight:number

LocalizedText
隐藏
只读
未复制
读取并联
功能: UI
TextButton.LocalizedText:string

MaxVisibleGraphemes
读取并联
功能: UI
TextButton.MaxVisibleGraphemes:number

OpenTypeFeatures
读取并联
功能: UI
TextButton.OpenTypeFeatures:string

OpenTypeFeaturesError
只读
未复制
读取并联
功能: UI
TextButton.OpenTypeFeaturesError:string

RichText
读取并联
功能: UI
TextButton.RichText:boolean

Text
读取并联
功能: UI
TextButton.Text:string
代码示例
渐隐横幅
local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"欢迎来到我的游戏!",
"确保玩得开心!",
"请给出建议!",
"要对其他玩家友好!",
"不要骚扰其他玩家!",
"查看商店!",
"提示:不要死亡!",
}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local RNG = Random.new()
local fadeIn = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 0,
})
local fadeOut = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 1,
})
local lastIndex
while true do
-- 步骤 0:在执行任何操作之前先淡出
fadeOut:Play()
task.wait(tweenInfo.Time)
-- 步骤 1:选择不是上一个显示的内容
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- 确保下次不显示相同的内容
lastIndex = index
-- 步骤 2:展示内容
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end
文本中的表情符号
local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "我感觉 " .. mood .. "! " .. face
task.wait(1)
end
end

TextBounds
只读
未复制
读取并联
功能: UI
TextButton.TextBounds:Vector2

TextColor
已弃用

TextColor3
读取并联
功能: UI
TextButton.TextColor3:Color3
代码示例
倒计时文本
-- 将此代码放置在 TextLabel/TextButton 内的 LocalScript 中
local textLabel = script.Parent
-- 一些我们用于 TextColor3 的颜色
local colorNormal = Color3.new(0, 0, 0) -- 黑色
local colorSoon = Color3.new(1, 0.5, 0.5) -- 红色
local colorDone = Color3.new(0.5, 1, 0.5) -- 绿色
-- 无限循环
while true do
-- 从 10 倒数到 1
for i = 10, 1, -1 do
-- 设置文本
textLabel.Text = "时间: " .. i
-- 根据剩余时间设置颜色
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "开始!"
textLabel.TextColor3 = colorDone
task.wait(2)
end

TextDirection
读取并联
功能: UI
TextButton.TextDirection:Enum.TextDirection

TextFits
只读
未复制
读取并联
功能: UI
TextButton.TextFits:boolean

TextScaled
读取并联
功能: UI
TextButton.TextScaled:boolean

TextSize
读取并联
功能: UI
TextButton.TextSize:number

TextStrokeColor3
读取并联
功能: UI
TextButton.TextStrokeColor3:Color3

TextStrokeTransparency
读取并联
功能: UI
TextButton.TextStrokeTransparency:number

TextTransparency
读取并联
功能: UI
TextButton.TextTransparency:number

TextTruncate
读取并联
功能: UI
TextButton.TextTruncate:Enum.TextTruncate

TextWrap
已弃用

TextWrapped
读取并联
功能: UI
TextButton.TextWrapped:boolean

TextXAlignment
读取并联
功能: UI
TextButton.TextXAlignment:Enum.TextXAlignment

TextYAlignment
读取并联
功能: UI
TextButton.TextYAlignment:Enum.TextYAlignment

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。