Apprendre
Classe de moteur
TextLabel

*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.


Échantillons de code
Texte de l'état du jeu
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Placez un StringValue appelé "GameState" dans le ReplicatedStorage
local vGameState = ReplicatedStorage:WaitForChild("GameState")
-- Placez ce code dans un TextLabel
local textLabel = script.Parent
-- Quelques couleurs que nous allons utiliser avec TextColor3
local colorNormal = Color3.new(0, 0, 0) -- noir
local colorCountdown = Color3.new(1, 0.5, 0) -- orange
local colorRound = Color3.new(0.25, 0.25, 1) -- bleu
-- Nous exécuterons cette fonction pour mettre à jour le TextLabel à mesure que l'état de
-- jeu change.
local function update()
-- Mettre à jour le texte
textLabel.Text = "État : " .. vGameState.Value
-- Définir la couleur du texte en fonction de l'état actuel du jeu
if vGameState.Value == "Countdown" then
textLabel.TextColor3 = colorCountdown
elseif vGameState.Value == "Round" then
textLabel.TextColor3 = colorRound
else
textLabel.TextColor3 = colorNormal
end
end
-- Modèle : mettre à jour une fois lorsque nous commençons et aussi lorsque vGameState change
-- Nous devrions toujours voir l'état du jeu le plus à jour.
update()
vGameState.Changed:Connect(update)

Référence API
Propriétés
ContentText
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextLabel.ContentText:string

Font
Caché
Non répliqué
Lecture parallèle
Capacités : UI
TextLabel.Font:Enum.Font
Échantillons de code
Afficher toutes les polices
local frame = script.Parent
-- Créer un TextLabel affichant chaque police
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Définir les propriétés du texte
textLabel.Text = font.Name
textLabel.Font = font
-- Certaines propriétés de rendu
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Ajuster la taille du cadre à la hauteur du texte
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Ajouter au cadre parent
textLabel.Parent = frame
end
-- Disposer les cadres dans une liste (s'ils ne le sont pas déjà)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end
Police de cycle
local textLabel = script.Parent
while true do
-- Itérer sur toutes les différentes polices
for _, font in pairs(Enum.Font:GetEnumItems()) do
textLabel.Font = font
textLabel.Text = font.Name
task.wait(1)
end
end

FontFace
Lecture parallèle
Capacités : UI
TextLabel.FontFace:Font

FontSize
Déprécié

LineHeight
Lecture parallèle
Capacités : UI
TextLabel.LineHeight:number

LocalizedText
Caché
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextLabel.LocalizedText:string

MaxVisibleGraphemes
Lecture parallèle
Capacités : UI
TextLabel.MaxVisibleGraphemes:number

OpenTypeFeatures
Lecture parallèle
Capacités : UI
TextLabel.OpenTypeFeatures:string

OpenTypeFeaturesError
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextLabel.OpenTypeFeaturesError:string

RichText
Lecture parallèle
Capacités : UI
TextLabel.RichText:boolean

Text
Lecture parallèle
Capacités : UI
TextLabel.Text:string
Échantillons de code
Bannière Fuyante
local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"Bienvenue dans mon jeu!",
"Assurez-vous de vous amuser!",
"Merci de donner des suggestions!",
"Soyez gentil avec les autres joueurs!",
"Ne détruisez pas les autres joueurs!",
"Découvrez le magasin!",
"Conseil : Ne mourrez pas!",
}
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
-- Étape 0 : Fuir avant de faire quoi que ce soit
fadeOut:Play()
task.wait(tweenInfo.Time)
-- Étape 1 : choisir un contenu qui n'était pas le dernier affiché
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- Assurez-vous de ne pas montrer la même chose la prochaine fois
lastIndex = index
-- Étape 2 : montrer le contenu
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end
Émoji dans le texte
local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "Je me sens " .. mood .. "! " .. face
task.wait(1)
end
end

TextBounds
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextLabel.TextBounds:Vector2
Échantillons de code
Taille de la Zone de Texte Dynamique
local textBox = script.Parent
-- La plus petite taille que la TextBox peut avoir
local minWidth, minHeight = 10, 10
-- Définit l'alignement pour que notre texte ne bouge pas un peu pendant que nous tapons
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextYAlignment = Enum.TextYAlignment.Top
local function updateSize()
textBox.Size = UDim2.new(0, math.max(minWidth, textBox.TextBounds.X), 0, math.max(minHeight, textBox.TextBounds.Y))
end
textBox:GetPropertyChangedSignal("TextBounds"):Connect(updateSize)

TextColor
Déprécié

TextColor3
Lecture parallèle
Capacités : UI
TextLabel.TextColor3:Color3
Échantillons de code
Texte de compte à rebours
-- Placez ce code dans un LocalScript à l'intérieur d'un TextLabel/TextButton
local textLabel = script.Parent
-- Certaines couleurs que nous utiliserons avec TextColor3
local colorNormal = Color3.new(0, 0, 0) -- noir
local colorSoon = Color3.new(1, 0.5, 0.5) -- rouge
local colorDone = Color3.new(0.5, 1, 0.5) -- vert
-- Boucle infinie
while true do
-- Comptez à rebours de 10 à 1
for i = 10, 1, -1 do
-- Définir le texte
textLabel.Text = "Temps : " .. i
-- Définir la couleur en fonction du temps restant
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "PARTEZ!"
textLabel.TextColor3 = colorDone
task.wait(2)
end

TextDirection
Lecture parallèle
Capacités : UI
TextLabel.TextDirection:Enum.TextDirection

TextFits
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextLabel.TextFits:boolean

TextScaled
Lecture parallèle
Capacités : UI
TextLabel.TextScaled:boolean

TextSize
Lecture parallèle
Capacités : UI
TextLabel.TextSize:number
Échantillons de code
"Kaboom!" Texte
local textLabel = script.Parent
textLabel.Text = "Kaboom!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
end

TextStrokeColor3
Lecture parallèle
Capacités : UI
TextLabel.TextStrokeColor3:Color3

TextStrokeTransparency
Lecture parallèle
Capacités : UI
TextLabel.TextStrokeTransparency:number
Échantillons de code
Oscillation de Mise en Évidence du Texte
local textLabel = script.Parent
-- À quelle vitesse la mise en évidence doit clignoter
local freq = 2
-- Définir la couleur de mise en évidence en jaune
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin oscille de -1 à 1, donc nous changeons la plage à 0 à 1 :
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
end

TextTransparency
Lecture parallèle
Capacités : UI
TextLabel.TextTransparency:number

TextTruncate
Lecture parallèle
Capacités : UI
TextLabel.TextTruncate:Enum.TextTruncate

TextWrap
Déprécié

TextWrapped
Lecture parallèle
Capacités : UI
TextLabel.TextWrapped:boolean
Échantillons de code
Long Text Wrapping
local textLabel = script.Parent
-- Cette démo de wrapping de texte est mieux montrée sur un rectangle de 200x50 px
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Un contenu à épeler
local content = "Voici une longue chaîne de mots qui "
.. "dépassera finalement la largeur de l'élément UI "
.. "et formera des sauts de ligne. Utile pour les paragraphes "
.. "qui sont vraiment longs."
-- Une fonction qui épellera le texte deux caractères à la fois
local function spellTheText()
-- Itérer de 1 à la longueur de notre contenu
for i = 1, content:len() do
-- Obtenir une sous-chaîne de notre contenu : 1 à i
textLabel.Text = content:sub(1, i)
-- Colorer le texte s'il ne rentre pas dans notre boîte
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Noir
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Rouge
end
-- Attendre un bref moment sur des longueurs paires
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Épelons le texte sans échelle/rapprochement
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Épelons le texte avec rapprochement
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Épelons le texte avec l'échelle de texte activée
-- Remarque : Le texte devient rouge (TextFits = false) une fois que le texte doit être
-- réduit pour s'adapter à l'élément UI.
textLabel.TextScaled = true
-- Remarque : TextWrapped est activé implicitement lorsque TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end

TextXAlignment
Lecture parallèle
Capacités : UI
TextLabel.TextXAlignment:Enum.TextXAlignment
Échantillons de code
Alignement du texte
-- Collez ceci dans un LocalScript au sein d'un TextLabel/TextButton/TextBox
local textLabel = script.Parent
local function setAlignment(xAlign, yAlign)
textLabel.TextXAlignment = xAlign
textLabel.TextYAlignment = yAlign
textLabel.Text = xAlign.Name .. " + " .. yAlign.Name
end
while true do
-- Itérer sur les éléments d'énumération TextXAlignment et TextYAlignment
for _, yAlign in pairs(Enum.TextYAlignment:GetEnumItems()) do
for _, xAlign in pairs(Enum.TextXAlignment:GetEnumItems()) do
setAlignment(xAlign, yAlign)
task.wait(1)
end
end
end

TextYAlignment
Lecture parallèle
Capacités : UI
TextLabel.TextYAlignment:Enum.TextYAlignment

©2026 Société Roblox. Roblox, le logo Roblox et Powering Imagination font partie de nos marques déposées aux États-Unis et dans d'autres pays.