Class · inherits StyleBase
StyleSheet
Aggregates StyleRules and can be linked to DataModel
trees to apply style properties to instances.
About StyleSheet
Aggregates StyleRules and can be linked to DataModel
trees to apply style properties to instances. Note that a StyleSheet may
exist outside the DataModel, but it cannot be derived or linked to a
DataModel tree in such a case.
Methods 2
GetDerives
() → List<StyleSheet>Returns an array of otherStyleSheetsfrom which theStyleSheetis derivingStyleRulesand token definitions.SetDerives
(derives: Instances) → ()Sets theStyleSheetto deriveStyleRulesand token definitions from one or more otherStyleSheets.Sets the
StyleSheetto deriveStyleRulesand token definitions from one or more otherStyleSheetsin the order they are listed. This method spawns the appropriateStyleDeriveinstances and sets their priorities to establish the specified derivations.local ReplicatedStorage = game:GetService("ReplicatedStorage") local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet") -- Create a tokens style sheet local tokensSheet = Instance.new("StyleSheet") tokensSheet.Name = "Tokens" tokensSheet.Parent = ReplicatedStorage -- Set tokens (attributes) on tokens sheet tokensSheet:SetAttribute("LightGray", Color3.new(0.9, 0.9, 0.9)) tokensSheet:SetAttribute("DarkGray", Color3.new(0.2, 0.2, 0.2)) -- Create theme style sheets 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 -- Set theme sheets to derive from tokens sheet lightThemeSheet:SetDerives({ tokensSheet }) darkThemeSheet:SetDerives({ tokensSheet }) local themeDerive = Instance.new("StyleDerive") themeDerive.Parent = coreSheet themeDerive.StyleSheet = lightThemeSheet -- Function to dynamically change the derived theme for the core sheet local function changeTheme() if themeDerive.StyleSheet == lightThemeSheet then themeDerive.StyleSheet = darkThemeSheet elseif themeDerive.StyleSheet == darkThemeSheet then themeDerive.StyleSheet = lightThemeSheet end endNote that if you've created a design using the Style Editor, the StyleSheet sheet in the Design folder of
ReplicatedStoragewill contain aStyleDeriveto the BaseStyleSheet also in the Design folder. When setting derives withSetDerives(), be sure to include the base style sheet in the spot of least priority in relation to otherStyleSheetsin thederivesarray.
StyleSheet also has every member of StyleBase. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.