TextButton

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

ปุ่มข้อความเป็นพี่น้องของ TextLabel ในเรื่องการเรนเดอร์ด้วยพฤติกรรมเพิ่มเติมของ GuiButton มันจะกำหนดคุณสมบัติการเรนเดอร์เดียวกับที่ TextLabel

คุณสามารถปิดการแสดงผลของข้อความโดยการตั้งค่า TextButton.TextTransparency เป็น 1 คุณจะได้รับรูปสี่เหลี่ยมผืนที่สามารถใช้เป็นปุ่มได้

ตัวอย่างโค้ด

This code sample allows a player to click a button which keeps track of how many times it has been clicked.

Click Counter

-- Place this code in a LocalScript in a TextButton
local textButton = script.Parent
local counter = 0
textButton.Text = "Click me!"
local function onActivated()
counter = counter + 1
textButton.Text = "Clicks: " .. counter
end
textButton.Activated:Connect(onActivated)

สรุป

คุณสมบัติ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    คัดลอกของ TextButton.Text ที่ประกอบด้วยสิ่งที่กำลังเรนเดอร์โดย TextButton

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    กำหนดตัวอักษรที่ใช้เพื่อเรนเดอร์ข้อความ

  • อ่านพร้อมๆ กัน

    กำหนดตัวอักษรที่ใช้เพื่อเรนเดอร์ข้อความ

  • อ่านพร้อมๆ กัน

    ปรับแต่งการจัดตำแหน่งของข้อความใน TextButton

  • ซ่อนอยู่
    อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ตั้งค่าว่า TextButton ควรเป็น GuiBase2d.Localize หรือไม่

  • อ่านพร้อมๆ กัน

    จํานวนสูงสุดของโกรมที่ TextButton สามารถแสดงได้

  • อ่านพร้อมๆ กัน
  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน
  • อ่านพร้อมๆ กัน

    กำหนดว่า TextButton จะเรนเดอร์สตริง TextButton.Text โดยใช้การจัดรูปแบบข้อความที่รวดเร็ว

  • อ่านพร้อมๆ กัน

    กำหนดสตริงที่เรนเดอร์โดยส่วนประกอบ UI

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ขนาดข้อความของส่วนหนึ่งของ UI ในออเฟ็ต

  • อ่านพร้อมๆ กัน

    กำหนดสีของข้อความที่เรนเดอร์

  • อ่านพร้อมๆ กัน
  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    การแทนที่ตัวอักษรของ TextButton ว่ามันเหมาะกับขนาดของมันหรือไม่

  • อ่านพร้อมๆ กัน

    เปลี่ยนว่าตัวอักษรจะปรับให้เข้ากับ TextButton หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดความสูงของตัวอักษรในออเฟ็ต

  • อ่านพร้อมๆ กัน

    กำหนดสีของเส้นข้อความ (ขอบเขต)

  • อ่านพร้อมๆ กัน

    กำหนดความโปร่งใสของเส้นข้อความ (ขอบเขต)

  • อ่านพร้อมๆ กัน

    กำหนดความโปร่งใสของข้อความที่เรนเดอร์

  • อ่านพร้อมๆ กัน

    ควบคุมการตัดข้อความใน TextButton นี้

  • อ่านพร้อมๆ กัน

    กำหนดว่าความหนาของข้อความเรียบร้อยไปยังหลายบรรทัดภายในพื้นที่ของ GUI หรือไม่ โดยการตัดข้อความเกิน

  • อ่านพร้อมๆ กัน

    กำหนดการจัดตำแหน่งของข้อความที่เรนเดอร์

  • อ่านพร้อมๆ กัน

    กำหนดตำแหน่งการจัดตั้งของเนื้อหาที่เรนเดอร์

คุณสมบัติรับทอดมาจากGuiButton
  • อ่านพร้อมๆ กัน

    กำหนดว่าปุ่มมีสีเมื่อเมาส์เลื่อนผ่านหรือคลิกปุ่มนั้น

  • อ่านพร้อมๆ กัน

    หากเป็นเช่นนั้นเมื่อรูปแบบ GUI ปรากฏขึ้นจะไม่มีการล็อคเมาส์จนกว่าปุ่มเมาส์ขวาจะลง

  • อ่านพร้อมๆ กัน

    ตัวแปรบูลีนที่ระบุว่ามีการเลือกตัวอักษรหรือไม่

  • อ่านพร้อมๆ กัน

    ตั้งค่าสไตล์ของ GuiButton ตามรายการสไตล์ล่วงหน้า

คุณสมบัติรับทอดมาจากGuiObject
  • อ่านพร้อมๆ กัน

    กำหนดว่ารูปแบบนี้สามารถรับข้อมูลการป้อนของผู้ใช้ได้หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดจุดเริ่มต้นของ GuiObject สัมพันธ์กับขนาดอันตามตัวเลข

  • อ่านพร้อมๆ กัน

    กำหนดว่าจะมีการปรับขนาดหรือไม่ขึ้นอยู่กับเนื้อหาของลูก

  • อ่านพร้อมๆ กัน

    กำหนดสีพื้นหลัง GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดความโปร่งใสของพื้นหลังและขอบเขตของ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดสีของขอบ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดวิธีการที่ GuiObject ขอบเขตถูกวางโดยเฉลี่ยกับขนาดของมัน

  • อ่านพร้อมๆ กัน

    กำหนดความกว้างของพิกเซลของ GuiObject รอบ

  • อ่านพร้อมๆ กัน

    กำหนดว่าควรเรนเดอร์หรือไม่ GuiObjects ภายนอกขอบเขตของรูปปั้น GUI ระดับพ่อของคุณ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    กำหนดว่าผู้เล่นกดเมาส์บน GuiObject หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดว่า GuiButton สามารถใช้งานได้หรือไม่ หรือว่า GuiState ของ GuiObject กําลังเปลี่ยนแปลงหรือไม่

  • อ่านพร้อมๆ กัน

    ควบคุมลำดับการเรียงลำดับของ GuiObject เมื่อใช้กับ UIGridStyleLayout

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะได้รับการเลือกเมื่อเครื่องยนต์ผู้ควบคุมเลื่อนลง

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนซ้าย

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนไปทางขวา

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนขึ้น

  • อ่านพร้อมๆ กัน

    กำหนดตำแหน่งพิกเซลและตำแหน่งเศษเส้นของ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดจำนวนองศาที่ GuiObject หมุน

  • อ่านพร้อมๆ กัน

    กำหนดว่า GUI สามารถเลือกได้โดย gamepad หรือไม่

  • อ่านพร้อมๆ กัน

    เปลี่ยนแปลงการตกแต่งการเลือกที่ใช้สำหรับแพดพันเกม

  • อ่านพร้อมๆ กัน

    ลำดับของ GuiObjects ที่เลือกโดย UI เกมแพด.

  • อ่านพร้อมๆ กัน

    กำหนดขนาดพิกเซลและขนาดพิกเซลของ GuiObject

  • อ่านพร้อมๆ กัน

    ตั้งค่า Size แกนที่ Class.GuiObject จะสร้างบน, สัมพันธ์กับขนาดของพ่อของมัน.

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน
    เลิกใช้แล้ว

    สมบัติสัมพันธ์ผสมของ BackgroundTransparency และ TextTransparency

  • อ่านพร้อมๆ กัน

    กำหนดว่า GuiObject และบุตรหลานของมันจะถูกเรนเดอร์หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดลำดับที่เรนเดอร์ GuiObject เมื่อเป็นคู่กับคนอื่น

คุณสมบัติรับทอดมาจากGuiBase2d
  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายตำแหน่งหน้าจอที่เป็นไปเลยของรายการ UI ในพิกเซล

  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายการหมุนเวียนหน้าจริงของ UI โดยองศา

  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายขนาดหน้าจอที่เป็นไปจริงของรายการ UI

  • อ่านพร้อมๆ กัน

    เมื่อตั้งค่าเป็น true จะใช้การแปลภาษาใน GuiBase2d และลูกหลานของมัน

  • อ่านพร้อมๆ กัน

    การอ้างอิงถึง LocalizationTable ที่จะใช้ในการประยุกต์การแปลอัตโนมัติสู่ GuiBase2d และลูกหลานของมัน

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักในแนวลง

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพานเกมในแนวโน้มทางซ้าย

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักเกมในทิศทางที่ถูกต้อง

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักในแนวตั้งขึ้น

  • อ่านพร้อมๆ กัน

    ช่วยให้คุณสามารถปรับแต่งการเคลื่อนไหวของแผงควบคุมเกม

วิธีการ

วิธีการรับทอดมาจากGuiObject

อีเวนต์

อีเวนต์รับทอดมาจากGuiButtonอีเวนต์รับทอดมาจากGuiObject
  • เกิดขึ้นเมื่อผู้ใช้เริ่มต้นใช้งานผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มคีย์บอร์ดลง, ฯลฯ)

  • ไฟร์เมื่อผู้ใช้เปลี่ยนวิธีการโต้ตอบผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มกล้อง, ฯลฯ)

  • ไฟร์เมื่อผู้ใช้หยุดใช้งานผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มคีย์บอร์ดลง, ฯลฯ)

  • จะเกิดขึ้นเมื่อผู้ใช้ย้ายเมาส์ไปที่องค์ประกอบ GUI

  • จะเกิดขึ้นเมื่อผู้ใช้ย้ายเมาส์ออกจากส่วน GUI

  • การเพิ่มเติมเมื่อผู้ใช้เคลื่อนเมาส์ไปยัง GUI เมื่ออยู่ภายในส่วนหนึ่งของ GUI

  • จะเกิดขึ้นเมื่อผู้ใช้เลื่อนเมาส์กลับเมื่อเมาส์อยู่เหนือ GUI เอเจนต์

  • จะเกิดขึ้นเมื่อผู้ใช้เลื่อนเมาส์ไปข้างหน้าเมื่อเมาส์อยู่เหนือรายการ GUI

  • จุดเกิดเหตุเมื่อ GuiObject ได้รับการโฟกัสด้วย Gamepad ตัวเลือก

  • ไฟร์เมื่อ Gamepad เลือกเปลี่ยนโฟกัสไปที่ GuiObject

  • เกิดขึ้นเมื่อผู้เล่นเริ่มต้น ดำเนินการต่อและหยุดการกด UI เป็นเวลานาน

  • TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นยกนิ้วของพวกเขาบนองค์ประกอบ UI

  • TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal

    เปิดเมื่อผู้เล่นทำการเลื่อนหรือดึงด้วยนิ้วสองนิ้วบน UI

  • TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการหมุนโดยใช้นิ้วสองนิ้วบนรูปปั้น

  • TouchSwipe(swipeDirection : Enum.SwipeDirection,numberOfTouches : number):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการเลื่อนสไนเปอร์บนองค์ประกอบ UI

  • TouchTap(touchPositions : Array):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการเลื่อนสายตาในส่วน UI

อีเวนต์รับทอดมาจากGuiBase2d
  • SelectionChanged(amISelected : bool,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal

    เกิดขึ้นเมื่อเลือกแผงควบคุมเกมเคลื่อนไปยัง, ออกหรือเปลี่ยนแปลงใน GuiBase2d หรือ GuiObjects ต้นได้

คุณสมบัติ

ContentText

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

สมบัตินี้ให้คำเลียนแบบของ TextButton.Text ที่มีสิ่งที่แสดงอยู่ในขณะนี้โดย TextButton ใช้สำหรับการเรนเดอร์ข้อความขั้นสูง

ตัวอย่าง

เมื่อ TextButton.RichText เปิดใช้งานสิ่งที่ TextButton.ContentText โปรไฟล์แสดงตัวอักษรที่ปรากฏให้กับผู้เล่น


<tbody>
<tr>
<td>ปลอม</td>
<td>\<b>สวัสดี,\<br/> โลก!\</b></td>
<td>\<b>สวัสดี,\<br/> โลก!\</b></td>
</tr>
<tr>
<td>จริง</td>
<td>\<b>สวัสดี,\<br/> โลก!\</b></td>
<td>สวัสดี, โลก!</td>
</tr>
</tbody>
ข้อความรวมข้อความContentText
ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน

สมบัติข้อความ เลือกตัวอักษรหนึ่งในหลายตัวอักษรที่กำหนดไว้ล่วงหน้าที่ UI จะเรนเดอร์ข้อความของมัน บางตัวอักษรมีตัวอักษรขนาดใหญ่, ตัวอักษรลอต, และ/หรือตัวอักษรเบา (เนื่องจากไม่มีคุณสมบัต

ยกเว้นตัวอักษร "Legacy" ตัวอักษรแต่ละตัวจะเรนเดอร์ข้อความด้วยความสูงเส้นข้ามเส้นเท่ากับคุณสมบัติ TextButton.TextSize ตัว "Code" เป็นตัวอักษร

คุณสมบัตินี้ได้รับการซิงค์กับคุณสมบัติ TextButton.FontFace เมื่อตั้งค่าตัวอักษร ตัวอักษรจะตั้งค่าเป็น Font.fromEnum(value)

ตัวอย่างโค้ด

This code sample sets a parent TextLabel's Font and Text properties to all the different fonts available.

Cycle Font

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.

Show All 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

อ่านพร้อมๆ กัน

สมบัติข้อมูลตัวอักษรใกล้เคียงกับสมบัติข้อมูลตัวอักษรในรายการตัวอักษร แต่สามารถตั้งค่าตัวอักษรที่ไม่มีอยู่ในรายการตัวอักษร

คุณสมบัตินี้ได้รับการซิงค์กับคุณสมบัติ TextButton.Font เมื่อตั้งค่า FontFace ฟอนต์จะตั้งค่าตามค่าเรียบร้อยของรายการ หรือไปที่ Enum.Font.Unknown หากไม่มีคู่

LineHeight

อ่านพร้อมๆ กัน

ควบคุมความสูงของตัวอักษรโดยเป็นจำนวนหลายของขนาดตัวอักษรใน TextButton การปรับแต่งความสูงของตัวอักษรจะเพิ่มขึ้นตามขนาดของตัวอักษรที่อยู่ระหว่างการเรียกใช้ โดยปกติค่าเริ

LocalizedText

ซ่อนอยู่
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

สมบัตินี้ตั้งค่าว่า TextButton ควรเป็น GuiBase2d.Localize หรือไม่

MaxVisibleGraphemes

อ่านพร้อมๆ กัน

คุณสมบัตินี้ควบคุมจำนวนเงินสูงสุดของกราฟีม (หรือหน่วยข้อความ) ที่ปรากฏบน TextButton มันจะนำเสนอให้เป็นวิธีที่ง่ายในการสร้าง "เอฟเฟกต์เครื่องพิมพ์" ที่มีตัวอักษรปรากฏขึ้น

การเปลี่ยนแปลงสมบัติจะไม่เปลี่ยนตำแหน่งหรือขนาดของเหลี่ยมที่มองเห็นได้ - การจัดเรียงจะถูกคำนวณเป็นเหมือนเหลี่ยมทั้งหมดมองเห็นได้

การตั้งค่าสมบัติที่ -1 จะปิดใช้งานขีดจำกัดและแสดงรวมของ TextButton.Text

ตัวอย่างโค้ด

This example uses TweenService to animate the grapheme count in a typewriter-like fashion.

The final grapheme count comes from a combination of the text object's ContentText property, which excludes style tags used for rich text, and utf8.len(), which returns the grapheme count.

Typewriter Effect with MaxVisibleGraphemes

local TweenService = game:GetService("TweenService")
local textObject = script.Parent
local tweenInfo = TweenInfo.new(
4, -- it takes 4 seconds for the effect to complete
Enum.EasingStyle.Sine, -- typing starts fast and slows near the end
Enum.EasingDirection.Out
)
local tween = TweenService:Create(textObject, tweenInfo, {
-- Final value should be the total grapheme count
MaxVisibleGraphemes = utf8.len(textObject.ContentText),
})
tween:Play()
tween.Completed:Wait()
-- Reset the value so it can be tweened again
textObject.MaxVisibleGraphemes = -1

OpenTypeFeatures

อ่านพร้อมๆ กัน

OpenTypeFeaturesError

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

RichText

อ่านพร้อมๆ กัน

สมบัตินี้กำหนดว่า TextButton จะเรนเดอร์สตริง TextButton.Text โดยการใช้การจัดรูปแบบตัวอักษรที่ซับซ้อน การจัดรูปแบบตัวอักษรใช้แท็กเรียบเรียงง่ายๆ เพื่อสไตล์ส่วนของ

เพื่อใช้ข้อความแบบรวมอยู่ในตัวอักษร TextButton.Text เพียงแค่รวมแท็กการจัดรูปในสตริง Class.TextButton.Text

Text

อ่านพร้อมๆ กัน

สมบัติคำของสตริงที่เรนเดอร์ไปยังหน้าจอจะถูกกำหนดโดย

มันเป็นไปได้ที่จะเรนเดอร์อิโมจิ (เช่น 😃) และสัญลักษณ์อื่น ๆ เหล่านี้ สัญลักษณ์เหล่านี้พิเศษไม่ได้รับผลกระทบจากคุณสมบัติ Class.TextButton.TextColor3</

สมบัตินี้อาจมีตัวอักษรใหม่ แต่ไม่สามารถพิมพ์ตัวอักษรใหม่ในหน้าต่างของ ลักษณะ ได้ เช่นเดียวกับ อาจ มี ตัวอักษร tab แต่จะเรนเดอร์เป็นพื้นที่แทน

ตัวอย่างโค้ด

This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.

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

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

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.

Show All 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.

Long Text Wrapping

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.

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

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

คุณสมบัติ TextBounds เท่านั้น สะท้อนขนาดของเนื้อหาที่เรนเดอร์ในออเฟ็ต ในคำอื่น หากคุณพยายามที่จะใส่ตัวอักษรในรูปสี่เหลี่ยม คุณสมบัตินี้จะสะท้อนขนาดขั้นต่ำของรูปสี่เหลี่ยมที่คุณต้องการใช้

โดยใช้ TextService:GetTextSize() , คุณสามารถคาดการณ์ว่า TextBounds จะอยู่บน TextLabel ที่มีสตริง, TextButton.Font และขนาดตัวอักษร และขนาดของเฟรม

ตัวอย่างโค้ด

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.

Dynamic TextBox Size

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

อ่านพร้อมๆ กัน

สมบัตินี้กำหนดสีของข้อความทั้งหมดที่เรนเดอร์โดย GUI องค์ประกอบ สมบัตินี้พร้อมกับ TextButton.Font และ

สำคัญที่ต้องเข้าใจว่าข้อความนี้อ่านได้ง่ายโดยผู้เล่น! ตรวจสอบให้แน่ใจว่าสีของข้อความนี้มีความเป็นกระจุกกระจายน้อยเกื

ตัวอย่างโค้ด

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).

Vowel Detector

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.

TextBox Secret Word

-- 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.

Countdown Text

-- 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.

Game State Text

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

อ่านพร้อมๆ กัน

TextFits

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

การแทนที่ตัวอักษรของ TextButton ว่ามันเหมาะกับขนาดของมันหรือไม่

TextScaled

อ่านพร้อมๆ กัน

แทนที่จะใช้ TextScaled เราขอแนะนำให้คุณพิจารณาใช้ AutomaticSize วิธีการใหม่ในการขยายขนาด UI ที่จะให้ผลลัพธ์ทางวิสัยทัศน์ที่ดีที่สุด

สมบัติข้อความขนาดข้อความกำหนดว่าจะปรับขนาดข้อความให้เหมาะสมกับพื้นที่ของรูปแบบ UI ทั้งหมด เมื่อเปิดใช้งานสมบัติข้อความนี้จะไม่สนใจ

เมื่อใช้สำหรับ UI ของพื้นที่หน้าจอ อาจเป็นไปได้ที่จะใช้ UITextSizeConstraint เพื่อจำกัดขนาดข้อความที่เป็นไปได้

TextScaled และ AutomaticSize

แนะนำให้ผู้พัฒนาหลีกเลี่ยงการใช้ TextScaled และปรับแต่ง UI เพื่อให้สามารถใช้สมบัติสมบัติขนาดอัตโนมัติได้มากขึ้น ด้านล่างคือความแตกต่างระหว่างสองสมบัติสมบัติ:

  • TextScaled ปรับแต่งเนื้อหา (ข้อความ) เพื่อรองรับ UI โดยไม่ต้องสงสัย หากเครื่องมือปรับแต่งขนาดเล็กเกินไป บางข้อความอาจไม่อ่านได้หากเครื่องมือปรับแต่งขนาดเล็กเกินไป
  • AutomaticSize ปรับขนาด UI เพื่อรองรับเนื้อหา

ด้วยขนาดอัตโนมัติคุณสามารถปรับแต่ง UI ของคุณเพื่อรองรับเนื้อหา (ข้อความ) ในขณะที่คุณยังคงใช้ขนาดตัวอักษรที่เหมาะสม

เราแนะนำให้คุณไม่ใช้ both TextScaled และ AutomaticSize บนวัตถุเดียวกัน หากคุณใช้ both โปรพีดีพี่ี่:

  • AutomaticSize กำหนดจำนวนพื้นที่สูงสุดที่ GuiObject สามารถใช้ได้ (ในกรณีนี้คือข้อความ)
  • TextScaled ใช้พื้นที่ที่กำหนดโดย AutomaticSize เพื่อปรับขนาดตัวอักษรให้เหมาะกับพื้นที่ที่มีอยู่ ซึ่งจะขยายไปยังขนาดตัวอักษรสูงสุด (100) หากไม่มีข้อจํากัด
  • ผลลัพธ์สุดท้ายจะเป็น: ตัวอักษรไปที่ขนาดตัวอักษร 100 และวัตถุ UI จะขยายเพื่อให้เข้ากับตัวอักษรนั้น

การใช้ both AutomaticSize และ TextScaled ในเวลาเดียวกันอาจทำให้เกิดความแตกต่างขนาดที่มากเกินไปเมื่อเวลา AutomaticSize ปิด

ตัวอย่างโค้ด

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.

Long Text Wrapping

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

อ่านพร้อมๆ กัน

สมบัติขนาดข้อความ กำหนดความสูงในออเฟ็ตของข้อความเดียว หน่วยอยู่ในออเฟ็ต ไม่ใช่จุด (ซึ่งใช้ในโปรแกรมการแก้ไขข้อความส่วนใหญ่) ตัวอักษร "รุ่นมรดก" ไม่รองรับสมบัตินี้

ตัวอย่างโค้ด

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

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 ตั้งค่าสีของเส้นหรือเงาของข้อความที่เรนเดอร์ สีนี้และ TextButton.TextStrokeTransparency กำหนดสมบัติสมบัติของเส้นหรือเงา

การเรนเดอร์ของตัวอักษรเริ่มต้นก่อนข้อความปกติและเป็นเพียง 4 การเรนเดอร์ของข้อความเดียวกันใน +/- 1 พิกเซลออฟเซ็ตในแต่ละทิศทาง การเรนเดอร์ของตัวอักษรเริ่มต้

ตัวอย่างโค้ด

This code sample oscillates a TextLabel's TextStrokeTransparency so that it blinks the highlight of a text.

Text Highlight Oscillation

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 ตั้งค่าความโปร่งใสของเส้นหรือเงาของตัวอักษรที่เรนเดอร์ได้ สมบัตินี้และ TextButton.TextStrokeColor3 กำหนดสมบัติของเส้นหรือเงาของตัวอักษร

การเรนเดอร์ลายเนื้อหนังดำสีขาวเป็นการเรนเดอร์ลายเนื

ตัวอย่างโค้ด

This code sample oscillates a TextLabel's TextStrokeTransparency so that it blinks the highlight of a text.

Text Highlight Oscillation

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

อ่านพร้อมๆ กัน

สีข้อความ3 ระบุความโปร่งใสของข้อความทั้งหมดที่เรนเดอร์โดยส่วนประกอบ UI นี้ สีนี้พร้อมกับ TextButton.Font และ TextButton.TextSize

ตัวอักษรที่เรืองแสงขึ้นเมื่อใช้ for-loop เป็นวิธีที่ยอดเยี่ยมในการดึงดูดความสนใจของผู้เล่นไปยังข้อความที่ปรากฏบนหน้าจอ


-- Count backwards from 1 to 0, decrementing by 0.1
for i = 1, 0, -0.1 do
textLabel.TextTransparency = i
task.wait(0.1)
end

ตัวอย่างโค้ด

This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.

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

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

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

TextTruncate

อ่านพร้อมๆ กัน

ควบคุมการตัดข้อความใน TextButton นี้

TextWrapped

อ่านพร้อมๆ กัน

เมื่อเปิดใช้งานสมบัติสมบัตินี้จะเรนเดอร์ข้อความในหลายบรรทัดภายในพื้นที่ของ GUI เพื่อให้ TextButton.TextBounds ไม่เกิน GuiBase2d.AbsoluteSize ของ UI เอเลเมนต์

สิ่งนี้สามารถดำเนินการได้โดยการแบ่งตัวอักษรยาวเป็นหลายตัวอักษร การแบ่งตัวอักษรจะเริ่มต้นด้วยช่องว่างขาว; หากคำยาวไม่ได้ถูกแบ่งเป็นหลายสาย คำนั้นจะถูกแบ่งเป็นหลายสาย

หากการแบ่งวรรคต่อไปจะทำให้ความสูงตัวอักษรที่ตรงขึ้นของข้อความ (ส่วนประกอบ Y ของ TextButton.TextBounds ) เกินความสูงของเอเลเมนต์ (ส่วนประกอบ Y ของ GuiBase2d.AbsoluteSize ) จึ

ตัวอย่างโค้ด

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.

Long Text Wrapping

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 กำหนดการจัดตำแหน่งของเนื้อหาในช่องว่างของ UI โดยใช้หน้าเนื้อหา (X-axis) ตัวอักษร มันทำงานได้เช่นเดียวกับสมบัติคำแนะนำของ CSS โดยมีค่าซ้าย ขวา แ

สมบัตินี้ใช้ร่วมกับ TextButton.TextYAlignment เพื่อระบุตำแหน่งข้อความในแกนทั้งสอง สมบัตินี้จะไม่ส่งผลต่อสมบัติที่อ่านเท่านั้น TextButton.TextBounds และ Class.TextButton.TextF

ตัวอย่างโค้ด

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.

Text Alignment

-- 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 กำหนดความสมดุลแนวตั้ง (Y เห�ียน) ของเนื้อหาที่เรนเดอร์ในพื้นที่ UI เอเจนต์ สำหรับด้านบนและด้านล่าง เนื้อหาจะถูกเรนเดอร์ให้เหมือนเป็นขอบของ UI

สมบัตินี้ใช้ร่วมกับ TextButton.TextXAlignment เพื่อระบุตำแหน่งข้อความในแกนทั้งสอง สมบัตินี้จะไม่ส่งผลต่อสมบัติที่อ่านเท่านั้น TextButton.TextBounds และ Class.TextButton.TextF

ตัวอย่างโค้ด

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.

Text Alignment

-- 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

วิธีการ

อีเวนต์