TextLabel

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

A TextLabel 渲染一個長方形,如 Frame ,帶有格式化文字。矩形可用於定義文字邊界、文字縮放()、包裝(>和對齊(>)。

此類別包含控制文字顯示的屬性,例如 FontTextColor3 。要顯示只有文字並隱藏背景矩形,請將 BackgroundTransparency 設為 1

一個 UITextSizeConstraint 對象可以用來限制啟用了 TextScaled 的文字大小。建議文字大小不低於 9 ,否則可能不會對許多用戶可見。

概要

屬性

屬性 繼承自 GuiObject

屬性

屬性 繼承自 GuiBase2d

屬性

方法

方法 繼承自 GuiObject

方法

活動

活動 繼承自 GuiObject

活動

活動 繼承自 GuiBase2d

活動

屬性

ContentText

唯讀
未複製
平行讀取
隱藏
未複製
平行讀取

範例程式碼

顯示所有字體

local frame = script.Parent
-- 創建一個顯示每個字體的文字標籤
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

平行讀取

LineHeight

平行讀取

LocalizedText

隱藏
唯讀
未複製
平行讀取

MaxVisibleGraphemes

平行讀取

OpenTypeFeatures

平行讀取

OpenTypeFeaturesError

唯讀
未複製
平行讀取

RichText

平行讀取

Text

平行讀取

範例程式碼

Fading Banner

local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"Welcome to my game!",
"Be sure to have fun!",
"Please give suggestions!",
"Be nice to other players!",
"Don't grief other players!",
"Check out the shop!",
"Tip: Don't die!",
}
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
-- Step 0: Fade out before doing anything
fadeOut:Play()
task.wait(tweenInfo.Time)
-- Step 1: pick content that wasn't the last displayed
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- Make sure we don't show the same thing next time
lastIndex = index
-- Step 2: show the content
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end
Emoji in Text

local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "I am feeling " .. mood .. "! " .. face
task.wait(1)
end
end

TextBounds

唯讀
未複製
平行讀取

TextColor3

平行讀取

範例程式碼

倒數文字

-- 將此代碼放置在 TextLabel/TextButton 內的本地腳本中
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 = "Time: " .. i
-- 根據剩餘時間設置顏色
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "GO!"
textLabel.TextColor3 = colorDone
task.wait(2)
end

TextDirection

平行讀取

TextFits

唯讀
未複製
平行讀取

TextScaled

平行讀取

TextSize

平行讀取

TextStrokeColor3

平行讀取

TextStrokeTransparency

平行讀取

TextTransparency

平行讀取

TextTruncate

平行讀取

TextWrapped

平行讀取

TextXAlignment

平行讀取

TextYAlignment

平行讀取

方法

活動