StyleRule
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
กำหนดคุณสมบัติสไตล์ที่เหนือกว่าคุณสมบัติในตัวอย่างที่ได้รับผลกระทบจากคุณสมบัติ Selector โปรปรียา
สรุป
คุณสมบัติ
จํานวนที่กําหนดวิธีที่คุณสมบัติของ StyleRule สามารถใช้เป็นสัดส่วนกับคุณสมบัติเดียวกันในอื่น ๆ StyleRulesค่าลําดับความสําคัญสูงกว่ามีลําดับความสําคัญก่อนค่าลําดับความสําคัญต่ํากว่า
สตริงที่ระบุว่าตัวอย่างใดที่ StyleRule ควรส่งผลกระทบต่อ
สตริงอ่านเฉพาะที่แสดงข้อผิดพลาดจากคุณสมบัติ Selector
วิธีการ
คืนสารานุกรมของคู่คีย์-ค่าที่อธิบายคุณสมบัติของ StyleRule
คืนค่าของคุณสมบัติเฉพาะใน StyleRule
ให้คุณประกาศและตั้งค่าคุณสมบัติหลายอย่างของ StyleRule ในครั้งเดียว
ส่งคืนคอลเลกชันของเกี่ยวข้อง StyleRules
สอดใส่ StyleRule ใหม่ลงในคอลเลกชันของกฎ
คล้ายกับ InsertStyleRule() แต่ให้คุณประกาศและตั้งค่าหลาย StyleRules พร้อมกัน
อีเวนต์
อีเวนต์รับทอดมาจากStyleBaseไฟเมื่อหนึ่งหรือมากกว่า StyleRules ถูกเปลี่ยนโดยเฉพาะใน StyleSheet หรือ StyleRule ที่เชื่อมต่อ
คุณสมบัติ
Priority
จํานวนที่กําหนดวิธีที่คุณสมบัติของ StyleRule สามารถใช้เป็นสัดส่วนกับคุณสมบัติเดียวกันในอื่น ๆ StyleRulesค่าลําดับความสําคัญสูงกว่ามีลําดับความสําคัญก่อนค่าลําดับความสําคัญต่ํากว่าตัวอย่างเช่น หาก ที่มีลําดับความสําคัญของ มีคุณสมบัติ ของ จะมีลําดับความสําคัญสูงกว่า ที่มีคุณสมบัติต่ํากว่า
Selector
สตริงที่ระบุว่าตัวอย่างใดที่ StyleRule ควรส่งผลกระทบต่อนี่อาจเป็นการผสมผสานของตัวเลือกและตัวรวมเพื่อจับคู่คุณลักษณะเช่นชื่อคลาสชื่อตัวอย่างและความสัมพันธ์ระหว่างระดับ
ตัวอย่างเช่น ".Container > ImageLabel.BlueOnHover:Hover" หมายถึงกฎสไตล์ที่ถูกยกเลิกทุก ImageLabel ที่เป็นลูกของแท็กติดตามด้วย Container ( .Container > ImageLabel ) และ ถูกติดตามด้วย BlueOnHover ( .BlueOnHover ) และ และ อยู่ในสถานะ Enum.GuiState.Hover ( :Hover )
ตัวเลือก
<th>คําอธิบาย</th><th>ตัวอย่าง</th></tr></thead><tbody><tr><td><code>[คลาส]</code></td><td>ตรงกับตัวอย่างของคลาส <code>Class.GuiObject</code> หรือ <code>Class.UIComponent</code> คลาส</td><td><code>"กรอบ"</code><code>"ปุ่มภาพ"</code><code>"UICorner"</code></td></tr><tr><td><code>.[tag]</code></td><td>จับคู่ตัวอย่าง <a href="/studio/properties#instance-tags">ที่มีแท็ก</a> ด้วยแท็ก <code>Class.CollectionService</code></td><td><code>"บรรจุภัณฑ์"</code><code>"บลูบนโฮเวอร์"</code></td></tr><tr><td><code>[ชื่อ] #</code></td><td>จับคู่ตัวอย่างของคลาสเฉพาะ <code>Class.Instance.Name</code></td><td><code>"#ModalFrame"</code><code>"#ปิดปุ่ม"</code></td></tr><tr><td><code>[สถานะ]:</code></td><td>จับคู่ตัวอย่างที่อยู่ในปัจจุบันใน <code>Enum.GuiState</code></td><td><code>":เลื่อน"</code></td></tr></tbody>
ตัวเลือก |
---|
ผู้รวม
<th>คําอธิบาย</th><th>ตัวอย่าง</th></tr></thead><tbody><tr><td><code>></code></td><td>จับคู่ตัวอย่างที่เป็น <b>ลูกโดยตรง</b> ของการจับคู่ตัวกรองก่อนหน้านี้</td><td width="40%"><code>“เฟรม > .Inventory”</code></td></tr><tr><td><code>>></code></td><td>จับคู่ตัวอย่างที่เป็น <b>ลูกหลาน</b> ของตัวกรองก่อนหน้า</td><td><code>“ปุ่มภาพ >> .BlueOnHover”</code></td></tr><tr><td><code>,</code></td><td>ระบุรายการของตัวเลือกอิสระหลายรายการสำหรับกฎสไตล์</td><td><code>“Frame.TagA, TextLabel.TagA”</code></td></tr><tr><td><code>::</code></td><td>สร้างตัวอย่าง <code>Class.UIComponent</code> ภายใต้การจับคู่ตัวกรองก่อนหน้าและใช้คุณสมบัติของกฎสไตล์ให้กับมัน</td><td><code>“กรอบ::UICorner”</code></td></tr></tbody>
ผู้รวม |
---|
ตัวอย่างโค้ด
The following example shows how to define a class selector which targets all TextButton instances and styles them with blue background and light grey text. To test, paste the code into a LocalScript which is a child of a ScreenGui located inside the StarterGui container.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local screenGui = script.Parent
local coreSheet = Instance.new("StyleSheet")
coreSheet.Parent = ReplicatedStorage
local styleLink = Instance.new("StyleLink")
styleLink.StyleSheet = coreSheet
styleLink.Parent = screenGui
local rule = Instance.new("StyleRule")
rule.Parent = coreSheet
-- Class selector
rule.Selector = "TextButton"
-- Set rule properties
rule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("335FFF"),
["TextColor3"] = Color3.fromHex("E1E1E1"),
["Size"] = UDim2.new(0.15, 0, 0, 40),
["BorderSizePixel"] = 0
})
local button = Instance.new("TextButton")
button.Text = "Main Menu"
button.Parent = screenGui
The following example shows how to define a tag selector which utilizes tags applied through CollectionService to target a TextButton tagged with ButtonPrimary. To test, paste the code into a LocalScript which is a child of a ScreenGui located inside the StarterGui container.
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local screenGui = script.Parent
local coreSheet = Instance.new("StyleSheet")
coreSheet.Parent = ReplicatedStorage
local styleLink = Instance.new("StyleLink")
styleLink.StyleSheet = coreSheet
styleLink.Parent = screenGui
local rule = Instance.new("StyleRule")
rule.Parent = coreSheet
-- Tag selector
rule.Selector = ".ButtonPrimary"
-- Set rule properties
rule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("FF0099"),
["TextColor3"] = Color3.fromHex("E1E1E1"),
["Size"] = UDim2.new(0.15, 0, 0, 40),
["BorderSizePixel"] = 0
})
local button = Instance.new("TextButton")
button.Text = "Main Menu"
button.Parent = screenGui
-- Apply tag to button
CollectionService:AddTag(button, "ButtonPrimary")
The following example shows how to define a UI modifier selector which applies a phantom UICorner instance to a Frame tagged with RoundedCorner20. To test, paste the code into a LocalScript which is a child of a ScreenGui located inside the StarterGui container.
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local screenGui = script.Parent
local coreSheet = Instance.new("StyleSheet")
coreSheet.Parent = ReplicatedStorage
local styleLink = Instance.new("StyleLink")
styleLink.StyleSheet = coreSheet
styleLink.Parent = screenGui
local rule = Instance.new("StyleRule")
rule.Parent = coreSheet
-- UI component selector
rule.Selector = "Frame.RoundedCorner20::UICorner"
-- Set rule property
rule:SetProperty("CornerRadius", UDim.new(0, 20))
-- Create frame
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0.4, 0, 0.2, 0)
frame.Parent = screenGui
-- Apply tag to frame
CollectionService:AddTag(frame, "RoundedCorner20")
วิธีการ
GetProperties
คืนสารานุกรมของคู่คีย์-ค่าที่อธิบายคุณสมบัติของ StyleRule ตัวอย่างเช่น:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- รับการอ้างอิงถึงกฎสไตล์local frameRule = coreSheet.Framelocal props = frameRule:GetProperties()print(props)--[[{["AnchorPoint"] = 0.5, 0,["BackgroundColor3"] = 1, 0, 0.25}]]
ส่งค่ากลับ
สารานุกรมของคู่ค่ากุญแจ-ค่าที่อธิบายคุณสมบัติของ StyleRule
GetProperty
คืนค่าของคุณสมบัติเฉพาะใน StyleRule
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- รับการอ้างอิงถึงกฎสไตล์local frameRule = coreSheet.Framelocal prop = frameRule:GetProperty("AnchorPoint")print(prop) --> 0.5, 0
พารามิเตอร์
ชื่อสตริงของคุณสมบัติ เช่น "AnchorPoint" หรือ "BackgroundColor3"
ส่งค่ากลับ
มูลค่าของคุณสมบัติ
SetProperties
คล้ายกับ SetProperty() แต่ให้คุณประกาศและกำหนดค่าตัวแปรหลายอย่างของ StyleRule ในครั้งเดียวแต่ละภารกิจควรเป็นคุณสมบัติที่ถูกต้องของสิ่งที่ได้รับผลกระทบ GuiObject หรือ UIComponent ( UICorner , UIGradient , เป็นต้น) และแต่ละค่าที่กำหนดควรตรงกับประเภทค่าของคุณสมบัติ ตัวอย่างเช่น Vector2 สำหรับ AnchorPoint หรือ Color3 สำหรับ BackgroundColor3
ความพยายามในการกำหนดชื่อคุณสมบัติที่ไม่ถูกต้องเช่น "AnchorPt" หรือ "BkColor" จะล้มเหลวอย่างเงียบ ๆประเภทการไม่ตรงกันเช่น CFrame สำหรับ AnchorPoint หรือ UDim2 สำหรับ BackgroundColor3 จะล้มเหลวเช่นกันและจะปรากฏข้อผิดพลาดในหน้าต่าง ออก
เพื่อตั้งค่า/อัปเดตเพียงหนึ่งคุณสมบัติของ StyleRule ดู SetProperty()
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- รับการอ้างอิงถึงกฎสไตล์local frameRule = coreSheet.Frame-- ตั้งค่าคุณสมบัติกฎframeRule:SetProperties({["AnchorPoint"] = Vector2.new(0.5, 0),["BackgroundColor3"] = Color3.new(1, 0, 0.25)})
โปรดทราบว่าคุณสามารถกำหนดค่า โทเค็น เป็นค่าคุณสมบัติผ่านคํานําหน้า $
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")-- ตั้งโทเค็น (ลักษณะ) บนแผ่นโทเค็นtokensSheet:SetAttribute("TopCenterAnchor", Vector2.new(0.5, 0))tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))-- รับการอ้างอิงถึงกฎสไตล์local frameRule = coreSheet.Frame-- ตั้งค่าคุณสมบัติกฎframeRule:SetProperties({["AnchorPoint"] = "$TopCenterAnchor",["BackgroundColor3"] = "$MainBackgroundColor"})
พารามิเตอร์
สารานุกรมของคู่ค่ากุญแจ-ค่าที่กำหนดคุณสมบัติที่จะตั้ง
ส่งค่ากลับ
SetProperty
ตั้งค่าคุณสมบัติใหม่ (หรือแก้ไขคุณสมบัติที่มีอยู่) สําหรับ StyleRuleพารามิเตอร์ name ควรเป็นคุณสมบัติที่ถูกต้องของสิ่งที่ได้รับผลกระทบ GuiObject หรือ UIComponent ( UICorner , UIGradient , เป็นต้น) และค่าที่กำหนดควรตรงกับประเภทค่าของคุณสมบัติ ตัวอย่างเช่น Vector2 สำหรับ AnchorPoint หรือ Color3 สำหรับ BackgroundColor3
ความพยายามในการกำหนดชื่อคุณสมบัติที่ไม่ถูกต้องเช่น "AnchorPt" หรือ "BkColor" จะล้มเหลวอย่างเงียบ ๆประเภทการไม่ตรงกันเช่น CFrame สำหรับ AnchorPoint หรือ UDim2 สำหรับ BackgroundColor3 จะล้มเหลวเช่นกันและจะปรากฏข้อผิดพลาดในหน้าต่าง ออก
เพื่อตั้งค่าคุณสมบัติหลายอย่างสำหรับ StyleRule ในครั้งเดียว ดู SetProperties()
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- รับการอ้างอิงถึงกฎสไตล์local frameRule = coreSheet.Frame-- ตั้งค่าคุณสมบัติกฎframeRule:SetProperty("BackgroundColor3", Color3.new(1, 0, 0.25))
โปรดทราบว่าคุณสามารถกำหนดค่า โทเค็น เป็นค่าคุณสมบัติผ่านคํานําหน้า $
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")-- ตั้งโทเค็นใหม่ (คุณสมบัติ) บนแผ่นโทเค็นtokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))-- รับการอ้างอิงถึงกฎสไตล์local frameRule = coreSheet.Frame-- ตั้งค่าคุณสมบัติกฎเพื่อใช้โทเค็นเป็นมูลค่าframeRule:SetProperty("BackgroundColor3, "$MainBackgroundColor")
พารามิเตอร์
ชื่อทรัพย์สินที่จะตั้งค่า เช่น "BackgroundColor3" .
ค่าคุณสมบัติที่จะตั้งค่า เช่น Color3.new(1, 0, 0.25) .