StyleSheet
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Aggregati StyleRules e può essere collegato a DataModel alberi per applicare proprietà di stile alle istanze.Si noti che un StyleSheet può esistere al di fuori del DataModel , ma non può essere derivato o collegato a un DataModel albero in tal caso.
Sommario
Proprietà
Metodi
Restituisce un array di altri StyleSheets da cui il StyleSheet deriva StyleRules e le definizioni di token.
Imposta il StyleSheet per derivare StyleRules e le definizioni di token da uno o più altri StyleSheets.
Metodi
Restituisce un array di associati StyleRules .
Inserisce un nuovo StyleRule nel array delle regole.
Simile a InsertStyleRule() ma ti consente di dichiarare e impostare più StyleRules contemporaneamente.
Eventi
Eventi provenienti da StyleBaseEventi
Si accende quando uno o più StyleRules è esplicitamente cambiato sul connesso StyleSheet o StyleRule .
Proprietà
Metodi
GetDerives
Restituisce un array di altri StyleSheets da cui il StyleSheet deriva StyleRules e le definizioni di token.
Restituzioni
Array di altri StyleSheets .
SetDerives
Imposta il StyleSheet per derivare StyleRules e definizioni di token da uno o più altri StyleSheets nell'ordine in cui sono elencati.Questo metodo genera le istanze appropriate StyleDerive e imposta le loro priorità per stabilire le derivazioni specificate.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- Crea una pagina di stile di token
local tokensSheet = Instance.new("StyleSheet")
tokensSheet.Name = "Tokens"
tokensSheet.Parent = ReplicatedStorage
-- Imposta i gettoni (attributi) sulla scheda dei gettoni
tokensSheet:SetAttribute("LightGray", Color3.new(0.9, 0.9, 0.9))
tokensSheet:SetAttribute("DarkGray", Color3.new(0.2, 0.2, 0.2))
-- Crea fogli di stile tematici
local lightThemeSheet = Instance.new("StyleSheet")
lightThemeSheet.Name = "LightTheme"
lightThemeSheet:SetAttribute("Background", "$LightGray")
lightThemeSheet.Parent = ReplicatedStorage
local darkThemeSheet = Instance.new("StyleSheet")
darkThemeSheet.Name = "DarkTheme"
darkThemeSheet:SetAttribute("Background", "$DarkGray")
darkThemeSheet.Parent = ReplicatedStorage
-- Imposta le schede tema per derivare dalla scheda token
lightThemeSheet:SetDerives({ tokensSheet })
darkThemeSheet:SetDerives({ tokensSheet })
local themeDerive = Instance.new("StyleDerive")
themeDerive.Parent = coreSheet
themeDerive.StyleSheet = lightThemeSheet
-- Funzione per cambiare dinamicamente il tema derivato per la foglia principale
local function changeTheme()
if themeDerive.StyleSheet == lightThemeSheet then
themeDerive.StyleSheet = darkThemeSheet
elseif themeDerive.StyleSheet == darkThemeSheet then
themeDerive.StyleSheet = lightThemeSheet
end
end
Nota che se hai creato un design utilizzando l'editor di stile Style Editor, la foglia StyleSheet nella cartella Design di ReplicatedStorage conterrà anche una StyleDerive per la BaseStyleSheet anche nella cartella Design .Quando impostare derives con SetDerives() , assicurati di includere la foglia di stile di base nell'area di minore priorità rispetto ad altre StyleSheets nell'array derives.
Parametri
Array di altri StyleSheets per derivare StyleRules e definizioni di token.