StyleRule
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
Selector özelliğinin etkilendiği örneklerdeki özellikleri geçersiz kılan stil özelliklerini tanımlar.
Özet
Özellikler
StyleRule özelliklerinin diğer StyleRules özelliklerine göre nasıl uygulanacağını belirleyen bir sayı.Daha yüksek öncelik değerleri daha düşüklerden önceliklidir.
Hangi örneklerin StyleRule etkilenmesi gerektiğini belirten bir dize.
Selector özellikten hata gösteren sadece okunur bir dize.
Yöntemler
StyleRule niteliklerini tanımlayan bir anahtar-değer çiftleri sözlüğü döndürür.
StyleRule 'de belirli bir özelliğin değerini döndürür.
Bir kerede çok sayıda StyleRule özelliğini ilan edip ayarlamanıza izin verir.
İlgili bir dizi StyleRules döndürür.
Kural dizisine yeni bir StyleRule ekler.
InsertStyleRule() benzer, ancak aynı anda birden fazla StyleRules ilan edip ayarlamanıza izin verir.
Etkinlikler
Şuradan alınan Etkinlikler: StyleBaseBağlı StyleRules veya StyleSheet üzerinde açıkça değiştirilen bir veya daha fazla StyleRule değiştirildiğinde ateş eder.
Özellikler
Priority
StyleRule özelliklerinin diğer StyleRules özelliklerine göre nasıl uygulanacağını belirleyen bir sayı.Daha yüksek öncelik değerleri daha düşüklerden önceliklidir.Örneğin, bir StyleRule önceliği 10 ile bir AnchorPoint özelliği olan bir
Selector
Hangi örneklerin StyleRule etkilenmesi gerektiğini belirten bir dize.Bunlar, sınıf adı, örnek adı ve hiyerarşi ilişkileri gibi özelliklere uyan bir karışım olabilir seçiciler ve kombinatörler.
Örneğin, ".Container > ImageLabel.BlueOnHover:Hover" etkili olarak tarz kuralı her ImageLabel etiketi üzerinde geçerli olur, çünkü Container ( .Container > ImageLabel ) ve etiketi üzerinde BlueOnHover ( .BlueOnHover ) ve etiketi üzerinde Enum.GuiState.Hover durumdadır ( :Hover ).
Seçiciler
<th>Açıklama</th><th>Örnekler</th></tr></thead><tbody><tr><td><code>[sınıf]</code></td><td>Bir <code>Class.GuiObject</code> veya <code>Class.UIComponent</code> sınıfının örneklerini eşleştirir.</td><td><code>"Çerçeve"</code><code>"Görüntü Düğmesi"</code><code>"UICorner"</code></td></tr><tr><td><code>.[etiket]</code></td><td>Eşleşen örnekler <a href="/studio/properties#instance-tags">etiketli</a> bir <code>Class.CollectionService</code> etiketi ile etiketlenir.</td><td><code>".Container"</code><code>".BlueOnHover"</code></td></tr><tr><td><code>[name]</code></td><td>Belirli bir <code>Class.Instance.Name</code> sınıfının örneklerini eşleştirir.</td><td><code>"#ModalFrame"</code><code>"#KapatmaButonu"</code></td></tr><tr><td><code>[devlet]</code></td><td>Mevcut bir <code>Enum.GuiState</code> içindeki eşleşen örnekler.</td><td><code>":Uç"</code></td></tr></tbody>
Seçici |
---|
Kombinatörler
<th>Açıklama</th><th>Örnekler</th></tr></thead><tbody><tr><td><code>></code></td><td>Önceki filtre eşleşmelerinin <b>doğrudan çocukları</b> olduğu durumlarda eşleşen örnekleri bulur.</td><td width="40%"><code>“Çerçeve > .Envanter”</code></td></tr><tr><td><code>>></code></td><td>Önceki filtre eşleşmelerinin <b>mirasçıları</b> olduğu durumlarda eşleşen örnekleri bulur.</td><td><code>“Resim Düğmesi >> .BlueOnHover”</code></td></tr><tr><td><code>,</code></td><td>Stil kuralı için çok sayıda bağımsız seçici listesi belirtir.</td><td><code>“Frame.TagA, TextLabel.TagA”</code></td></tr><tr><td><code>::</code></td><td>Önceki filtre maçları altında bir hayalet <code>Class.UIComponent</code> sınıfı oluşturur ve stil kuralının özelliklerini ona uygular.</td><td><code>“Çerçeve::UICorner”</code></td></tr></tbody>
Kombinatör |
---|
Kod Örnekleri
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")
Yöntemler
GetProperties
Örneğin StyleRule 'nin özelliklerini tanımlayan bir anahtar-değer çiftleri sözlüğü döndürür:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- Stil kuralına referans alınlocal frameRule = coreSheet.Framelocal props = frameRule:GetProperties()print(props)--[[{["AnchorPoint"] = 0.5, 0,["BackgroundColor3"] = 1, 0, 0.25}]]
Dönüşler
StyleRule niteliklerini tanımlayan anahtar-değer çiftleri sözlüğü.
GetProperty
StyleRule 'de belirli bir özelliğin değerini döndürür.
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- Stil kuralına referans alınlocal frameRule = coreSheet.Framelocal prop = frameRule:GetProperty("AnchorPoint")print(prop) --> 0.5, 0
Parametreler
Özelliklerin dize adı, örneğin "AnchorPoint" veya "BackgroundColor3".
Dönüşler
Özelliğin değeri.
SetProperties
SetProperty() benzer, ancak aynı anda StyleRule çok sayıda özellik ilan edip ayarlamanıza izin verir.Her görev, etkilenen GuiObject veya UIComponent ( UICorner , UIGradient , vb.) için geçerli bir özellik olmalıdır ve her atanan değer, özelliğin değer türüne uymalıdır, örneğin Vector2 için AnchorPoint veya Color3 için BackgroundColor3.
"AnchorPt" veya "BkColor" gibi geçersiz özellik adları atamaya çalışmak sessizce başarısız olacaktır. örneğin için veya için başarısız olacak ve Çıktı penceresinde bir hata oluşacak.
Sadece bir StyleRule özelliğini ayarlamak/güncellemek için, bakınız SetProperty() .
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- Stil kuralına referans alınlocal frameRule = coreSheet.Frame-- Kural özelliklerini ayarlaframeRule:SetProperties({["AnchorPoint"] = Vector2.new(0.5, 0),["BackgroundColor3"] = Color3.new(1, 0, 0.25)})
Not etmeniz gerekir ki jetonları özellik değerleri olarak $:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")-- Jetonları (özellikleri) jeton tablosuna ayarlatokensSheet:SetAttribute("TopCenterAnchor", Vector2.new(0.5, 0))tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))-- Stil kuralına referans alınlocal frameRule = coreSheet.Frame-- Kural özelliklerini ayarlaframeRule:SetProperties({["AnchorPoint"] = "$TopCenterAnchor",["BackgroundColor3"] = "$MainBackgroundColor"})
Parametreler
Tanımlanacak özellikleri ayarlayan anahtar-değer çiftlerinin sözlüğü. Dictionary of key-value pairs defining the properties to set.
Dönüşler
SetProperty
StyleRule için yeni bir özellik ayarlar (veya mevcut bir özelliği değiştirir) veya .The name parametresi etkilenen GuiObject veya UIComponent ( UICorner , UIGradient , vb.) için geçerli bir özellik olmalıdır ve atanan değer özelliğin değer türüne uymalıdır, örneğin Vector2 için AnchorPoint veya Color3 için BackgroundColor3.
"AnchorPt" veya "BkColor" gibi geçersiz özellik adları atamaya çalışmak sessizce başarısız olacaktır. örneğin için veya için başarısız olacak ve Çıktı penceresinde bir hata oluşacak.
Bir kez StyleRule çok sayıda özellik ayarlamak için, bakınız SetProperties().
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- Stil kuralına referans alınlocal frameRule = coreSheet.Frame-- Kural özelliğini ayarlaframeRule:SetProperty("BackgroundColor3", Color3.new(1, 0, 0.25))
Not etmeniz gerekir ki jetonları özellik değerleri olarak $:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")-- Jeton (özellik) sayfasına yeni jeton ayarlatokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))-- Stil kuralına referans alınlocal frameRule = coreSheet.Frame-- Jetonun değeri olarak kullanmak için kural özelliğini ayarlaframeRule:SetProperty("BackgroundColor3, "$MainBackgroundColor")
Parametreler
Örneğin ayarlanacak özellik adı "BackgroundColor3".
Örneğin ayarlanacak özellik değeri Color3.new(1, 0, 0.25) .