TextBox
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
Bir Metin Kutusu , oyuncunun metin girişi yapmasına izin verir.Bir tek TextBox'un tıklayarak, dokunarak veya oyun kumandası seçimiyle odaklanması dışında, benzer şekilde davranır TextButton .Odaklanırken, oyuncu Text özelliğini değiştirmek için bir klavye kullanabilir.
- Metin yoksa, PlaceholderText görünecektir. Bu, oyunculara girmeleri gereken veri türü veya formatı konusunda yararlı bir uyarıdır.
- Varsayılan olarak, ClearTextOnFocus özelliği etkinleştirilir ve bir TextBox odaklandığında mevcut bir metin olmadığından emin olur.oyuncutarafından düzenlenebilecek metin için bu istenmeyebilir.
- The MultiLine özelliği, oyuncuların yeni satır karakterleriyle birden fazla satır metin girmesine izin verir (\n).
The ContextActionService onur TextBox tuş kombinasyonlarını ve otomatik olarak anahtar basma olaylarının ContextActionService:BindAction() ile bağlı eylemlere geçmesini engelleyecektir.UserInputService.InputBegan ve ilgili olaylar, bir TextBox odakta olduğu sürece hala ateşlenecek.
Odak Durumu
Bir TextBox'un odak durumunu tespit edip değiştirmek mümkündür:
- Bir diyalog göründüğünde CaptureFocus kullanabilirsiniz, böylece oyuncu mevcut olduğunda bir TextBox'a tıklamak zorunda kalmaz; bu işlevi kullanarak bir TextBox'a odaklanmak için belirli bir anahtarı bağlamak için ContextActionService:BindAction() kullanabilirsiniz.Bir TextBox odaklanınca, Focused etkinliği ateşlenir.
- Belli bir TextBox'un odakta olup olmadığını IsFocused kullanarak tespit edebilirsiniz. Alternatif olarak, herhangi bir TextBox'un odakta olup olmadığını kontrol etmek için UserInputService:GetFocusedTextBox() kullanılabilir.
- Oyuncu metin girişini bitirdiğinde, etkinliği ateşlenir, kullanıcının odak kaybına neden olan ile birlikte metin göndermek için basıp basmadığını gösterir.Mobil ve konsolda ekran klavyelerini kullanırken, ReturnPressedFromOnScreenKeyboard da ateşlenebilir.
- oynanışsırasında daha önemli bir konu ortaya çıkarsa, bir oyuncunun klavye girişi oyununuza geri döner, TextBox'un ReleaseFocus kısmını öyle yapabilirsiniz.
Metin Düzenleme
Bir TextBox, CursorPosition ve SelectionStart özellikleri aracılığıyla metin seçimi destekler.GetPropertyChangedSignal kullanarak, bir seçimin değiştiğini tespit edebilirsiniz.Ayrıca, oyuncuların bir TextBox içinde metin kopyalayıp yapıştırması ve temel klip desteği sağlaması mümkündür.
Metin Filtreleme Bildirimi Oyuncudan oyuncuya iletişimi kolaylaştıran metinler, özel sohbet veya isim etiketleri gibi, bu tür bir metni doğru bir şekilde filtrelemelidir TextService:FilterStringAsync() veya Chat:FilterStringAsync() .Bu doğru yapılmazsa, oyununuz moderasyon aksiyonalabilir.
Kod Örnekleri
This code sample creates a password-like interface for a TextBox, giving visual feedback on the player's input.
-- Place this code in a LocalScript inside a TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- white
local colorWrong = Color3.new(1, 0, 0) -- red
local colorCorrect = Color3.new(0, 1, 0) -- green
-- Initialize the state of the textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "What is the secret word?"
textBox.BackgroundColor3 = colorNormal
local function onFocused()
textBox.BackgroundColor3 = colorNormal
end
local function onFocusLost(enterPressed, _inputObject)
if enterPressed then
local guess = textBox.Text
if guess == secretWord then
textBox.Text = "ACCESS GRANTED"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCESS DENIED"
textBox.BackgroundColor3 = colorWrong
end
else
-- The player stopped editing without pressing Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)
Özet
Özellikler
Metin Kutusuna tıklamanın onun TextBox.Text özelliğini temizleyip temizlemeyeceğini belirler.
Metin imlecinin baytlarındaki ofsetini belirler veya -1 yoksa imleç yoktur.
Metin görüntülemek için kullanılan yazı tipini belirler.
Metin görüntülemek için kullanılan yazı tipini belirler.
TextBox içindeki metin satırları arasındaki boşluk ölçeklendirilir.
TextBox'nin gösterebileceği maksimum grafem sayısı.
Doğru ayarlanırsa, bir TextBox içindeki metin çoklu satırlara taşınabilir. Bu da oyuncuların yeni bir satıra geçmek için girme tuşunu kullanmasına izin verir.
TextBox'a henüz hiçbir metin girişi yapılmadığında kullanılacak yazı rengini ayarlar.
TextBox'a henüz hiçbir metin girişi yapılmadığında görüntülenen metni ayarlar.
TextBox'un zengin metin biçimlendirme kullanarak TextBox.Text dizeyi görüntüleyip görüntülemediğini belirler.
Bir metin seçiminin başlangıç konumunu veya hiçbir metin seçilmediğinde -1 belirler.
Doğru olarak ayarlanırsa, platforma yerleşik klavye yerine Roblox'un dahili olarak yüklendiği klavyesi kullanılır.
Arayüz öğesi tarafından görüntülenen dizeyi belirler.
Bir UI öğesinin metninin ofsetlerdeki boyutu.
Görüntülenen metinin rengini belirler.
Kullanıcının Text 'yi değiştirebileceğini belirler.
Metnin TextBox sınırlarına uyup uymadığı.
Metnin, onu görüntüleyen GUI nesnesine uyacak şekilde yeniden boyutlandırılıp yeniden boyutlandırılmadığını değiştirir.
Ofsetlerdeki metin yüksekliğini belirleyin.
Metin darbesinin (çizginin) rengini belirler (çizgi).
Metin darbesinin (çizginin) transparanlığını belirler (çizgi).
Rendelenmiş metnin transparanlığını belirler.
Bu TextBox'ta gösterilen metnin kısaltılmasını kontrol eder.
Metnin GuiObject öğe alanı içinde birden fazla satıra sarılıp sarılmadığını belirler ve fazla metni kısaltır.
Rendelenmiş metnin yatay hizalanmasını belirler.
Rendelenmiş metnin dikey yerleşimini belirler.
Bu UI öğesinin girişi alıp almadığını belirler.
Bir GuiObject 'in mutlak boyutuna göre kaynağı noktasını belirler, mutlak boyutuna göre.
Yeniden boyutlandırmanın çocuk içeriğine dayalı olup olmadığını belirler.
GuiObject arka plan rengini belirler.
GuiObject arka planının ve sınırının saydamlığını belirler.
GuiObject sınırının rengini belirler.
GuiObject sınırının boyutlarına göre nasıl düzenleneceğini belirler.
GuiObject sınırının piksel genişliğini belirler.
Ebeveyn bir GUI öğesinin sınırlarının dışında olup olmadığına bakarak altının GuiObjects renderlanması gereip geremediğini belirler.
oyuncumouse'unun GuiObject üzerinde aktif olarak basılıp basılmadığını belirler.
GuiButton ile etkileşime girilebilir olup olmadığını veya GuiState 'nin değişip değişmediğini belirler, ya da GuiObject 'nin değişip değişmediği.
Bir GuiObject ile kullanıldığında UIGridStyleLayout sıralama düzenini kontrol eder.
Oyun kolu seçicisi aşağıya kaydırıldığında seçilecek GuiObject ayarını ayarlar
Oyun kolu seçicisinin sola taşındığında seçilecek GuiObject ayarını ayarlar
Oyun kolu seçicisinin sağa taşındığında seçilecek GuiObject ayarını ayarlar
Oyun kolu seçicisi yukarı taşındığında seçilecek GuiObject ayarını ayarlar
GuiObject 'nin piksel ve skalar konumunu belirler.
GuiObject döndürüldüğünde döndürülen derece sayısını belirler.
GuiObject bir oyun kolu tarafından seçilebilir olup olmadığını belirleyin.
Oyun konsolları için kullanılan varsayılan seçim aksesuarlarını değiştirir.
Oyun kumanda UI seçimi tarafından seçilen GuiObjects sırası.
GuiObject 'nin piksel ve skalar büyüklüğünü belirler.
Size eksenlerini ayarlar, üzerinde ebeveynin boyutuna göre yapılacak GuiObject , ebeveynin boyutuna göre yapılacak
BackgroundTransparency ve TextTransparency 'in karışık bir özelliği.
GuiObject ve onun soyundakilerin render edilecek olup olmadığını belirler.
Bir GuiObject'nin diğerlerine göre hangi sırayla görüntüleneceğini belirler.
Bir GuiBase2d öğesinin gerçek ekran konumunu, piksel olarak tanımlar.
Bir GuiBase2d öğesinin gerçek ekran dönüşünü derecelerle tanımlar.
Bir GuiBase2d öğesinin gerçek ekran boyutunu, piksel olarak tanımlar.
true olarak ayarlanırsa, yerelleştirme bu GuiBase2d ve onun soyundakilere uygulanacaktır.
Bu GuiBase2d ve onun soyundakilere otomatik yerelleştirme uygulamak için kullanılacak bir LocalizationTable.
Aşağı yönünde oyun kolu seçim davranışını özelleştirir.
Oyun kolu seçim davranışını sol yönde özelleştirir.
Oyun kolu seçim davranışını doğru yönde özelleştirir.
Oyun kolu seçim davranışını yukarı yönünde özelleştirir.
Oyun kolu seçim hareketinin özelleştirilmesine izin verir.
Yöntemler
Müşteriyi TextBox'a odaklanmaya zorlar.
Metin kutusu odaklanmışsa gerçek döndürür, değilse yalan.
Müşteriyi TextBox'tan uzaklaştırmaya zorlar.
- TweenPosition(endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
Bir GUI'yi yumuşakça yeni bir UDim2 'ye taşır.
- TweenSize(endSize : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
Bir GuiObject 'yi yumuşak bir şekilde yeni bir UDim2 'ye yeniden boyutlandırır.
- TweenSizeAndPosition(endSize : UDim2,endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
Bir GUI'yi yumuşakça yeni bir boyuta ve konuma taşır.
Etkinlikler
Müşteri odaklarını TextBox terk etmesine izin verdiğinde ateş eder.
TextBox odak kazandığında ateş eder.
Bir kullanıcı, İnsan-Bilgisayar Arayüzü cihazı aracılığıyla etkileşime başladığında ateş edilir (Fare düğmesi aşağı, dokunma başlar, klavye düğmesi aşağı, vb.).
Bir kullanıcı, İnsan-Bilgisayar Arayüzü cihazı aracılığıyla nasıl etkileşime girdiğini değiştirdiğinde ateş edilir (Fare düğmesü aşağı, dokunma başlar, klavye düğmesi aşağı, vb.).
Bir kullanıcı, İnsan-Bilgisayar Arayüzü cihazı aracılığıyla etkileşime son verdiğinde ateş edilir (Mouse düğmes aşağı, dokunma başlar, klavye düğmesi aşağı, vb.).
Bir kullanıcının fareini bir GUI öğesine taşıdığında ateş eder.
Bir kullanıcı GUI öğesinden fareni taşıdığında ateş eder.
Bir kullanıcı bir GUI öğesinin içindeyken fareyi hareket ettirdiğinde herhangi bir zamanda ateş eder.
Bir kullanıcı, fare bir GUI öğesinin üzerinde olduğunda fare tekerleğini geri sürüklediğinde ateş eder.
Bir kullanıcı, fare işaretçisi bir GUI öğesinin üzerinde olduğunda fare tekerleğini ileriye doğru kaydırdığında ateş eder.
GuiObject, Gamepad seçicisi ile odaklanırken ateş edildi.
Oyun Konsolu seçicisi GuiObject'e odaklanmayı bıraktığında ateş edilir.
Oyuncu başladığında, devam ettiğinde ve uzun süre UI öğesine basmayı bıraktığında ateş eder.
- TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal
Oyuncu UI öğesine parmağını hareket ettirdiğinde ateş eder.
- TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
Oyuncu, UI öğesinde iki parmağı kullanarak bir kıskaç veya çekme hareketi gerçekleştirdiğinde ateş eder.
- TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
Oyuncu, UI öğesinde iki parmağı kullanarak bir dönüş hareketi gerçekleştirdiğinde ateş eder.
Oyuncu UI öğesine kaydırma hareketi yaptığında ateş eder.
Oyuncu UI öğesine dokunma hareketi yaptığında ateş eder.
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
Oyun kolu seçimi, hareket eder, değişir veya bağlantılı GuiBase2d veya herhangi bir altın içinde değişir, bağlantılı GuiObjects .
Özellikler
ContentText
CursorPosition
Bu özellik, metin imlecinin baytlar halinde ofsetini belirler veya eğer şu anda düzenlenmiyorsa.1 değeri, Text özelliğindeki ilk bayttan önceki konumu temsil eder.SelectionStart özelliği ile birlikte kullanıldığında, hem seçilen metni hem de bir TextBox içinde almak ve ayarlamak mümkündür.
Bu özelliğin birimlerinin bayt ve emoji gibi birçok Unicode karakterinin 1 bayttan daha uzun olduğunu unutmayın.durum, bir oyuncu "Merhaba👋" ("Merhaba" hemen ardından dalgalanan el işaretiyle takip edilir) yazarsa, kurör pozisyonu 10 olacaktır, 7 değil, çünkü emoji 4 bayt kullanır.
Kod Örnekleri
This code sample demonstrates reading the current selection of a TextBox using CursorPosition() and SelectionStart().
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("No selection")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('The selection is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)
Font
Yazıtipi özelliği, UI öğesinin metni görüntüleyeceği birkaç önceden tanımlanmış fonts arasından birini seçer.Bazı yazı tipleri bold, italik ve/veya hafif varyantlara sahiptir (font-weight veya font-style özellikleri olmadığı için).
Miras" yazı tipi hariç, her yazı tipi, TextBox.TextSize özelliğinin eşit uzunluğundaki metni görüntüleyecektir.Kod tipi tek boşluklu yazı tipidir. "Code" font is the only monospace font.Her karakterin aynı genişlik ve yükseklik oranına sahip olması gerektiği benzersiz bir özelliğe sahiptir: 1:2.Her karakterin genişliği yaklaşık olarak TextBox.TextSize özelliğinin yarısıdır.
Bu özellik, TextBox.FontFace özelliği ile senkronize edilir. Yazı Tipi ayarlanırken, FontFace Font.fromEnum(value) olarak ayarlanacaktır.
Kod Örnekleri
This code sample sets a parent TextLabel's Font and Text properties to all the different fonts available.
local textLabel = script.Parent
while true do
-- Iterate over all the different fonts
for _, font in pairs(Enum.Font:GetEnumItems()) do
textLabel.Font = font
textLabel.Text = font.Name
task.wait(1)
end
end
This code sample renders a list of all the available fonts.
local frame = script.Parent
-- Create a TextLabel displaying each font
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Set the text properties
textLabel.Text = font.Name
textLabel.Font = font
-- Some rendering properties
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Size the frame equal to the height of the text
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Add to the parent frame
textLabel.Parent = frame
end
-- Layout the frames in a list (if they aren't already)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end
FontFace
FontFace özelliği, Font özelliğine benzer, ancak Font enum'de bulunmayan fontları ayarlamaya izin verir.
Bu özellik, TextBox.Font özelliği ile senkronize edilir.FontFace ayarlandığında, yazı tipi ilgili en sayı değerine ayarlanır veya eşleşme yoksa Enum.Font.Unknown .
LineHeight
Kontroller, yazı tipinin em kare boyutunun bir katı olarak çizgilerin yüksekliğini kontrol eder, çizgiler arasındaki mesafeyi TextBox 'de arttırarak.Geçerli değerler 1.0 ile 3.0 arasında değişir, varsayılan olarak 1.0.
MaxVisibleGraphemes
Bu özellik, TextBox 'de gösterilen maksimum grafem sayısını (veya metin birimlerini) kontrol eder, TextBox.PlaceholderText veya TextBox.Text gösterip göstermediğine bakılmaksızın.
Özellik değiştirmek, görünen grafemlerin konumunu veya boyutunu değiştirmez - düzen, tüm grafemler görünebilir gibi hesaplanacaktır.
Özelliği -1 olarak ayarlamak, sınırı devre dışı bırakır ve tümünü TextBox.Text gösterir.
MultiLine
Doğru ayarlanırsa, bir TextBox içindeki metin çoklu satırlara taşınabilir. Bu da oyuncuların yeni bir satıra geçmek için girme tuşunu kullanmasına izin verir.
OpenTypeFeatures
OpenTypeFeaturesError
PlaceholderColor3
TextBox'a henüz hiçbir metin girişi yapılmadığında kullanılacak yazı rengini ayarlar.
RichText
Bu özellik, TextBox ın zengin metin biçimlendirme kullanarak TextBox.Text dizeyi görüntüleyip görüntülemediğini belirler.Zengin metin, içeriğin kalın, italik, belirli renkler ve daha fazlası için bölümlerini biçimlendirmek için basit işaretleme etiketleri kullanır.
Zengin metni kullanmak için, basitçe biçimlendirme etiketlerini TextBox.Text diziekleyin.
Not that when the TextBox has this property enabled and the box gains focus, the user will be able to edit and interact with the complete XML dizi, including all of the formatting tags.Odak kaybolduğunda, metin etiketleri otomatik olarak zengin metin olarak parçalayacak ve gösterecektir.
SelectionStart
Bir metin seçiminin başlangıç konumunu veya TextBox'un seçilen metin aralığı olmadığı durumda -1'i belirler.Değer -1 veya eşdeğerse CursorPosition , seçilen metin aralığı yoktur.Bu özellik, CursorPosition ile aynı konumlandırma mantığını kullanır.SeçimBaşlangıcı, kur포zisyonu seçimin başlangıcında ise CursorPosition'dan daha büyük, kurpozisyonu bitirise CursorPosition'dan daha az olacaktır.
Kod Örnekleri
This code sample demonstrates reading the current selection of a TextBox using CursorPosition() and SelectionStart().
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("No selection")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('The selection is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)
ShowNativeInput
Doğru olarak ayarlanırsa, platforma yerleşik klavye yerine Roblox'un dahili olarak yüklendiği klavyesi kullanılır.
Text
Metin özelliği, UI öğesi tarafından sunulan içeriği belirler.Ekrana gösterilen dize görsel özellikleri ile TextBox.TextColor3 , TextBox.TextTransparency , TextBox.TextSize , TextBox.Font , TextBox.TextScaled , TextBox.TextWrapped , TextBox.TextXAlignment ve TextBox.TextYAlignment belirlenir.
Emoji'leri (örneğin, 😃) ve diğer sembolleri göstermek mümkündür.Bu özel semboller TextBox.TextColor3 özelliğinden etkilenmez.Bunlar Script ve LocalScript nesnelerine, ayrıca Özellikler penceresindeki alana yapıştırılabilir.
Bu özellik yeni satır karakterleri içerebilir, ancak Özellikler penceresinde yeni satır karakterlerini yazmak mümkün değildir.Benzer şekilde, bu özellik bir sekme karakteri içerebilir, ancak yerine boşluk olarak görünecektir.
Kod Örnekleri
This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.
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
This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.
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
This code sample renders a list of all the available fonts.
local frame = script.Parent
-- Create a TextLabel displaying each font
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Set the text properties
textLabel.Text = font.Name
textLabel.Font = font
-- Some rendering properties
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Size the frame equal to the height of the text
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Add to the parent frame
textLabel.Parent = frame
end
-- Layout the frames in a list (if they aren't already)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end
This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.
local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end
This code sample demonstrates emoji rendering using the Text property.
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
Sadece okuma özelliği TextBounds, ofsetlerde sunulan kaba metin boyutunu yansıtır.Diğer bir deyişle, metni bir dikdörtgen içine sığdırmaya çalışırsanız, bu özellik, metni sığdırmak için ihtiyacınız olan dikdörtgenin minimum boyutunu yansıtacaktır.
TextService:GetTextSize() kullanarak, TextBounds'un bir TextLabel'e verilen bir dizi, TextBox.Font , TextBox.TextSize ve çerçeve boyutu üzerinde ne olacağını tahmin edebilirsiniz.
Kod Örnekleri
This code sample dynamically resizes a TextLabel, TextButton or TextBox to match the size of its TextBounds. Try changing the minimum width/height and pasting into a LocalScript in a TextBox.
local textBox = script.Parent
-- The smallest the TextBox will go
local minWidth, minHeight = 10, 10
-- Set alignment so our text doesn't wobble a bit while we type
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)
TextColor3
Bu özellik, bir GuiObject elemanı tarafından görüntülenen tüm metinin rengini belirler.Bu özellik, TextBox.Font , TextBox.TextSize ve TextBox.TextTransparency ile birlikte, metnin görsel özelliklerini belirleyecektir.Metin, metin darbesinden sonra görüntülenir ( TextBox.TextStrokeColor3 ).
Metnin oyuncular tarafından kolayca okunması önemlidir! Beyaz, gri veya siyah gibi az veya çok saturasyonlu renkler seçin.Metnin renginin UI öğesinin TextBox.BackgroundColor3 tarafından kontrastlandığından emin olun.Elemanın saydam bir arka planı varsa, arkasındaki 3B dünyayla metni kontrastlandırmaya yardımcı olmak için siyah bir TextBox.TextStrokeColor3 uygulayın.
Kod Örnekleri
This code sample, when placed within a TextBox, will turn the text color red if the typed string contains no vowels (A, E, I, O or U).
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Check for vowels
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Red
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)
This code sample creates a password-like interface for a TextBox, giving visual feedback on the player's input.
-- Place this code in a LocalScript inside a TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- white
local colorWrong = Color3.new(1, 0, 0) -- red
local colorCorrect = Color3.new(0, 1, 0) -- green
-- Initialize the state of the textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "What is the secret word?"
textBox.BackgroundColor3 = colorNormal
local function onFocused()
textBox.BackgroundColor3 = colorNormal
end
local function onFocusLost(enterPressed, _inputObject)
if enterPressed then
local guess = textBox.Text
if guess == secretWord then
textBox.Text = "ACCESS GRANTED"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCESS DENIED"
textBox.BackgroundColor3 = colorWrong
end
else
-- The player stopped editing without pressing Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)
This code sample makes a TextLabel or TextButton count backwards from 10, setting the text color as it does so.
-- Place this code in a LocalScript within a TextLabel/TextButton
local textLabel = script.Parent
-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorSoon = Color3.new(1, 0.5, 0.5) -- red
local colorDone = Color3.new(0.5, 1, 0.5) -- green
-- Loop infinitely
while true do
-- Count backwards from 10 to 1
for i = 10, 1, -1 do
-- Set the text
textLabel.Text = "Time: " .. i
-- Set the color based on how much time is left
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
This code sample mirrors the contents of a StringValue into a TextLabel, updating and setting the color of the text as it changes.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Place a StringValue called "GameState" in the ReplicatedStorage
local vGameState = ReplicatedStorage:WaitForChild("GameState")
-- Place this code in a TextLabel
local textLabel = script.Parent
-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorCountdown = Color3.new(1, 0.5, 0) -- orange
local colorRound = Color3.new(0.25, 0.25, 1) -- blue
-- We'll run this function to update the TextLabel as the state of the
-- game changes.
local function update()
-- Update the text
textLabel.Text = "State: " .. vGameState.Value
-- Set the color of the text based on the current game state
if vGameState.Value == "Countdown" then
textLabel.TextColor3 = colorCountdown
elseif vGameState.Value == "Round" then
textLabel.TextColor3 = colorRound
else
textLabel.TextColor3 = colorNormal
end
end
-- Pattern: update once when we start and also when vGameState changes
-- We should always see the most updated GameState.
update()
vGameState.Changed:Connect(update)
TextDirection
TextEditable
Düzenlenebilir Metin kullanıcının giriş yoluyla değiştirebileceği Text ı belirler.Bu özellik devre dışı bırakıldığında ClearTextOnFocus kapatılması önerilir, aksi takdirde metin odaklanırken temizlenebilir.Bu özellik, oyun içinde kopyalanabilen içerikten okunur kutular oluşturmak için yararlıdır.This property is useful to make read-only TextBoxes from which content can be copied in-game.
TextScaled
TextScaled kullanmak yerine, mümkün olan en iyi görsel sonucu verecek yeni bir yöntem olan AutomaticSize kullanmayı düşünmenizi öneririz.
TextScaled özelliği, metnin tüm UI öğesinin alanını dolduracak şekilde ölçeklendirilip ölçeklendirilmediğini belirler.Bunun etkinleştirildiğinde, TextBox.TextSize göz ardı edilir ve TextBox.TextWrapped otomatik olarak etkinleştirilir.Bu özellik, BillboardGuis içindeki metin görüntüleme UI öğeleri için yararlıdır.
Bu özellik ekran-uzayı arayüzü için kullanıldığında, olası metin boyutu aralığını sınırlandırmak için bir UITextSizeConstraint kullanmak istenebilir.
MetinÖlçeklendirildi ve OtomatikBoyut
Geliştiricilerin TextScaled kullanımından kaçınması ve bunun yerine Otomatik Boyut özelliğinden yararlanmak için UI'yi ayarlamaları önerilir.İki özellik arasındaki temel farklar aşağıdadır:
- TextScaled, içeriği (metin) UI'ye uyacak şekilde ölçeklendirir. Dikkatli bir şekilde düşünülmeden, bazı metinler çok küçük ölçeklendirildiğinde okunaksız hale gelebilir.
- Otomatik Boyut, arayüzü içeriği barındırmak için yeniden boyutlandırır.
Otomatik Boyut ile, kullanıcı arayüzünüzü tutarlı bir font boyutu koruyarak içeriği (metin) barındırmak için ayarlayabilirsiniz.Otomatik boyutlandırmanın nasıl kullanılacağına ilişkin daha fazla bilgi için, UI Otomatik Boyut makalesine bakın.
Her iki özelliği de aynı UI nesnesine uygulamayacağınızı öneririz: Her iki özellik de uygularsanız:
- Otomatik Boyut, bir GuiObject'nin kullanabileceği maksimum alan miktarını belirler (bu durumda, metin)
- TextScaled, Otomatik Boyut tarafından belirlenen mevcut alanı genişletmek için kullanılabilir alanı kullanarak, yazı boyutunu mevcut alana uyacak şekilde ölçeklendirir, ki bu da maksimum yazı boyutuna (100) genişleyecektir, eğer boyut sınırları yoksa
- Sonuç şöyle olacak: metin 100 karakter boyutuna gider ve UI nesnesi bu metne uyacak şekilde genişleyecek
Her iki otomatik büyüklük ve TextScaled'ı aynı anda kullanmak, Otomatik Büyüklüğün kapalı olduğundan daha önemli ölçek farklarına neden olabilir.
Kod Örnekleri
This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.
local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end
TextSize
TextSize özelliği, bir satır görüntülenen metnin ofsetlerindeki yüksekliği belirler.Birim ofsetlerde, noktalarda değil (çoğu belge düzenleme programında kullanılır).Miras" yazı tipi bu özelliği tutmuyor.
Kod Örnekleri
This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.
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
TextStrokeColor3 özelliği, görüntülenen metnin çizgisinin veya hatlarının rengini ayarlar.Bu özellik ve TextBox.TextStrokeTransparency metin çizginin görsel özelliklerini belirler.
Metin darbesi normal metinden önce görüntülenir ve basitçe aynı metnin +/- 1 piksel ofsetinde her yönde 4 render'dır.Metin çizgisi renderleme bağımsız ve aynı şekilde çalışır TextBox.TextColor3 ve TextBox.TextTransparency .
Kod Örnekleri
This code sample oscillates a TextLabel's TextStrokeTransparency so that it blinks the highlight of a text.
local textLabel = script.Parent
-- How fast the highlight ought to blink
local freq = 2
-- Set to yellow highlight color
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin oscillates from -1 to 1, so we change the range to 0 to 1:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
end
TextStrokeTransparency
TextStrokeTransparency özelliği, görüntülenen metnin çizginin veya hatlarının transparanlığını ayarlar.Bu özellik ve TextBox.TextStrokeColor3 metin çizginin görsel özelliklerini belirler.
Metin darbesi normal metinden önce görüntülenir ve basitçe aynı metnin +/- 1 piksel ofsetinde her yönde 4 render'dır.Metin çizgisi renderleme bağımsız ve aynı şekilde çalışır TextBox.TextColor3 ve TextBox.TextTransparency .Metin darbesi basitçe aynı saydamlığın birden fazla görüntüsüdür, bu nedenle bu özellik temelde kendi üzerinde dört kez çarpan olur (örneğin0.5'lik bir TextStrokeTransparency, 0.0625'in TextTransparency'i veya 0.5^4 ile aynı görünüyor).Bu nedenle, daha ince bir etki için TextStrokeTransparency değerini 0.75 ile 1 arasında bir değere ayarlamak önerilir.
Kod Örnekleri
This code sample oscillates a TextLabel's TextStrokeTransparency so that it blinks the highlight of a text.
local textLabel = script.Parent
-- How fast the highlight ought to blink
local freq = 2
-- Set to yellow highlight color
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin oscillates from -1 to 1, so we change the range to 0 to 1:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
end
TextTransparency
TextColor3 özelliği, bir UI öğesi tarafından görüntülenen tüm metinlerin saydamlığını belirler.Bu özellik, TextBox.Font , TextBox.TextSize ve TextBox.TextColor3 ile birlikte, metnin görsel özelliklerini belirleyecektir.Metin, metin darbesinden sonra görüntülenir ( TextBox.TextStrokeTransparency ).
Bir sayısal for döngüsü kullanarak kaybolan metin, ekranda görünen bir oyuncunun dikkatini çekmek için harika bir yoldur.
-- Count backwards from 1 to 0, decrementing by 0.1for i = 1, 0, -0.1 dotextLabel.TextTransparency = itask.wait(0.1)end
Kod Örnekleri
This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.
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
This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.
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
TextWrapped
Aktifleştirildiğinde, bu özellik bir elemanının alanında çoklu satırlarda metin görüntüleyecek, böylece GUI öğesinin sınırı asla aşılmayacaktır.
Bu, uzun metin parçalarını birden fazla satıra ayırarak elde edilir.Satır bozuklukları boşluk tercih edecektir; uzun kesilmemiş bir kelime elemanın genişliğini aşarsa, bu kelime birden fazla satıra bölünecektir.
Daha fazla satır bozulması, metnin ( 'nin Y bileşeninin) yatay yüksekliğinin, elemanın yatay yüksekliğini aşmasına neden olursa, o satır hiç tümü.
Kod Örnekleri
This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.
local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end
TextXAlignment
TextXAlignment, bir UI öğesinin alanı içinde görüntülenen metnin yatay hizalanmasını (X eksen) belirler.Sol, sağ ve orta değerlerle CSS metin hizalama özelliğine benzer şekilde işler (uzatma seçeneği yoktur).Sol ve sağ için, metin, sol/sağ metin sınırlarının sadece UI öğesi kenarına dokunması şekilde görüntülenir.Merkez için, her bir metin satırı UI öğesi dikdörtgeninin orta noktasına odaklanır.
Bu özellik, her iki eksende de metin yerleşimini tamamen belirlemek için TextBox.TextYAlignment ile birlikte kullanılır.Bu özellik okuma-sadece özelliklerini etkilemez TextBox.TextBounds ve TextBox.TextFits .
Kod Örnekleri
This code sample shows all the different text alignment combinations by iterating over each enum item. It is meant to be placed within a TextLabel, TextButton or TextBox.
-- Paste this in a LocalScript within a 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
-- Iterate over both TextXAlignment and TextYAlignment enum items
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
TextYAlignment, bir UI öğesinin alanı içinde görüntülenen metnin yatay yerleşimini (Y eksen) belirler.Üst ve Alt için, metin üst/alt metin sınırları sadece UI öğesi kenarına dokunacak şekilde görüntülenir.Merkez için, metin, metnin üst sınırlarından elementin üstüne ve metnin alt sınırlarından elementin altına eşit bir uzaklıkta görüntülenir.
Bu özellik, her iki eksende de metin yerleşimini tamamen belirlemek için TextBox.TextXAlignment ile birlikte kullanılır.Bu özellik okuma-sadece özelliklerini etkilemez TextBox.TextBounds ve TextBox.TextFits .
Kod Örnekleri
This code sample shows all the different text alignment combinations by iterating over each enum item. It is meant to be placed within a TextLabel, TextButton or TextBox.
-- Paste this in a LocalScript within a 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
-- Iterate over both TextXAlignment and TextYAlignment enum items
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
Yöntemler
CaptureFocus
Müşteriyi TextBox'a odaklanmaya zorlar.
Dönüşler
Kod Örnekleri
This code sample causes the client to focus on the parent TextBox when the Q key is pressed by the player.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_NAME = "FocusTheTextBox"
local textBox = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_NAME and inputState == Enum.UserInputState.End then
textBox:CaptureFocus()
end
end
ContextActionService:BindAction(ACTION_NAME, handleAction, false, Enum.KeyCode.Q)
ReleaseFocus
Müşteriyi TextBox'tan uzaklaştırmaya zorlar. submitted parametresi, enterPressed parametresini TextBox.FocusLost etkinliğinde geçersiz kılmanıza izin verir.
Bu öğe, online modda beklenen şekilde çalışması için bir LocalScript ile kullanılmalıdır.
Aşağıda gösterilen kod, seçildikten 5 saniye sonra istemiyi 'TextBox' odaklanmaktan çıkaracaktır:
local TextBox = script.Parent
TextBox.Focused:Connect(function()
wait(5)
TextBox:ReleaseFocus()
end)
Lütfen yukarıdaki örnek bir TextBox'un çocuğu olarak bir YerelScript'te olduğunu varsaydığını unutmayın.
Parametreler
Dönüşler
Kod Örnekleri
The code shown below will force the client to unfocus the 'TextBox' 5 seconds after it's selected:
local textBox = script.Parent
local function onFocused()
task.wait(5)
textBox:ReleaseFocus()
end
textBox.Focused:Connect(onFocused)
Etkinlikler
FocusLost
Müşteri odaklarının TextBox'tan ayrılmasına izin verdiğinde ateş eder - tipik olarak bir müşteri TextBox dışında tıklar/dokunur.Ayrıca, bir TextBox kullanıcıya odaklanmasını zorlarsa da ateş eder.
Bir TextBox kazandığında ve kaybettiğinde takip etmek için TextBox.Focused ile birlikte kullanılabilir.
Ayrıca, UserInputService.TextBoxFocused ve UserInputService.TextBoxFocusReleased kullanıcı giriş hizmetine dayalı benzer işlevler için göz atın.
Bu olay yalnızca bir LocalScript içinde kullanıldığında ateşlenecektir.
Parametreler
Müşterinin odak kaybetmek için Enter'a basıp basmadığını gösteren bir boşluk veya değil ( yanlış) ifadesi olan bir Boolean.
TextBox'un odak kaybına neden olan giriş türünü gösteren bir InputObject örneği.
Kod Örnekleri
The example shown below will print "Focus was lost because enter was pressed!" whenever the TextBox loses focus as a result of the enter key being pressed.
local gui = script.Parent
local textBox = gui.TextBox
local function focusLost(enterPressed)
if enterPressed then
print("Focus was lost because enter was pressed!")
else
print("Focus was lost without enter being pressed")
end
end
textBox.FocusLost:Connect(focusLost)
This example works when placed in a LocalScript that is the child of a TextBox. When the TextBox loses focus, the example prints either:
- "Player pressed Enter" - if the TextBox lost focus because the player pressed the Enter key. or
- "Player pressed InputObject.KeyCode" - where "KeyCode" is the InputObject KeyCode property of the input that caused the TextBox to lose focus. For example, pressing the Escape (esc) key to exit TextBox focus returns an InputObject instance with the KeyCode 'InputObject.Escape'.
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Player pressed Enter")
else
print("Player pressed", inputThatCausedFocusLost.KeyCode)
end
end
textBox.FocusLost:Connect(onFocusLost)
Focused
TextBox odak kazandığında ateş eder - genellikle bir müşteri, bir TextBox'a tıklayarak/dokunarak metin girişine başlamak için.Ayrıca, bir TextBox kullanıcıya odaklanmasını zorlarsa da ateş eder.
Bir TextBox kazandığında ve kaybettiğinde takip etmek için TextBox.FocusLost ile birlikte kullanılabilir.
Ayrıca, UserInputService.TextBoxFocused ve UserInputService.TextBoxFocusReleased kullanıcı giriş hizmetine dayalı benzer işlevler için göz atın.
Bu olay yalnızca bir LocalScript içinde kullanıldığında ateşlenecektir.
Kod Örnekleri
This example works when placed in a LocalScript that is the child of a TextBox. When the TextBox gains focus, the example prints "Focus".
local textBox = script.Parent
local function onFocused()
print("Focused")
end
textBox.Focused:Connect(onFocused)