学习
引擎类
StyleRule

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处


概要
方法
GetProperty(name: string):Variant
SetDefaultPropertyTransition(transitionParams: Variant):()
SetProperties(styleProperties: Dictionary):()
SetProperty(name: string,value: Variant):()
SetPropertyTransition(property: string,transitionParams: Variant):()
继承成员

API 参考
属性
Priority
读取并联
功能: UI
StyleRule.Priority:number

Selector
读取并联
功能: UI
StyleRule.Selector:string
代码示例
用户界面类选择器
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
-- 类选择器
rule.Selector = "TextButton"
-- 设置规则属性
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 = "主菜单"
button.Parent = screenGui
UI 标签选择器
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
-- 标签选择器
rule.Selector = ".ButtonPrimary"
-- 设置规则属性
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 = "主菜单"
button.Parent = screenGui
-- 将标签应用于按钮
CollectionService:AddTag(button, "ButtonPrimary")
UI 修改器选择器
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 组件选择器
rule.Selector = "Frame.RoundedCorner20::UICorner"
-- 设置规则属性
rule:SetProperty("CornerRadius", UDim.new(0, 20))
-- 创建框架
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0.4, 0, 0.2, 0)
frame.Parent = screenGui
-- 将标签应用于框架
CollectionService:AddTag(frame, "RoundedCorner20")
UI 样式查询选择器
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 smallRule = Instance.new("StyleRule")
smallRule.Parent = coreSheet
local mediumRule = Instance.new("StyleRule")
mediumRule.Parent = coreSheet
-- 声明样式查询选择器
smallRule.Selector = "@Small"
mediumRule.Selector = "@Medium"
-- 设置规则属性
smallRule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("FF0099"),
["Text"] = "小容器",
["TextColor3"] = Color3.fromHex("E1E1E1"),
["TextSize"] = 12,
})
mediumRule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("F0F0F0"),
["Text"] = "中型容器",
["TextColor3"] = Color3.fromHex("0022FC"),
["TextSize"] = 24,
})
local button = Instance.new("TextButton")
button.Text = "主菜单"
button.Parent = screenGui
button.Size = UDim2.fromScale(0.5, 0.2)
-- 创建样式查询,名称与样式规则选择器匹配
local mediumSQ = Instance.new("StyleQuery")
mediumSQ.Parent = button
mediumSQ.Name = "Medium"
mediumSQ:SetConditions({
["MinSize"] = Vector2.new(200, 0),
})
local smallSQ = Instance.new("StyleQuery")
smallSQ.Parent = button
smallSQ.Name = "Small"
smallSQ:SetConditions({
["MaxSize"] = Vector2.new(200, math.huge),
["MinSize"] = Vector2.new(0, 0),
})

SelectorError
只读
未复制
读取并联
功能: UI
StyleRule.SelectorError:string

方法
GetDefaultPropertyTransition
功能: UI
StyleRule:GetDefaultPropertyTransition():Variant
返回
Variant

GetProperties
功能: UI
StyleRule:GetProperties():Dictionary

GetProperty
功能: UI
StyleRule:GetProperty(name:string):Variant
参数
name:string
返回
Variant

GetPropertyTransitions
功能: UI
StyleRule:GetPropertyTransitions():Dictionary
代码示例
获取属性过渡()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
-- 设置一些过渡
frameRule:SetPropertyTransition("BackgroundColor3", TweenInfo.new(1, Enum.EasingStyle.Linear))
frameRule:SetPropertyTransition("BackgroundTransparency", "$DefaultTransition")
local transitions = frameRule:GetPropertyTransitions()
print(transitions)

SetDefaultPropertyTransition
功能: UI
StyleRule:SetDefaultPropertyTransition(transitionParams:Variant):()
参数
transitionParams:Variant
返回
()

SetProperties
功能: UI
StyleRule:SetProperties(styleProperties:Dictionary):()
参数
styleProperties:Dictionary
返回
()

SetProperty
功能: UI
StyleRule:SetProperty(
name:string, value:Variant
):()
参数
name:string
value:Variant
返回
()

SetPropertyTransition
功能: UI
StyleRule:SetPropertyTransition(
property:string, transitionParams:Variant
):()
参数
property:string
transitionParams:Variant
返回
()
代码示例
设置属性过渡(SetPropertyTransition)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
-- 对 BackgroundColor3 设置 1 秒的线性过渡
frameRule:SetPropertyTransition("BackgroundColor3", TweenInfo.new(
1, -- 时间
Enum.EasingStyle.Linear -- 缓动样式
))
-- 移除过渡
frameRule:SetPropertyTransition("BackgroundColor3", nil)
使用令牌的 SetPropertyTransition()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")
-- 在令牌表上设置令牌(属性)
tokensSheet:SetAttribute("LinearTransition", TweenInfo.new(1, Enum.EasingStyle.Linear))
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
frameRule:SetPropertyTransition("BackgroundColor3", "$LinearTransition")

SetPropertyTransitions
功能: UI
StyleRule:SetPropertyTransitions(properties:Dictionary):()
参数
properties:Dictionary
返回
()
代码示例
设置属性过渡()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
-- 同时设置两个属性的过渡
frameRule:SetPropertyTransitions({
["BackgroundColor3"] = TweenInfo.new(1, Enum.EasingStyle.Linear),
["BackgroundTransparency"] = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
})
-- 移除所有过渡
frameRule:SetPropertyTransitions({})
使用令牌的 SetPropertyTransitions()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
local tokenSheet = ReplicatedStorage:FindFirstChild("Tokens")
-- 在令牌表上设置令牌(属性)
tokenSheet:SetAttribute("LinearTransition", TweenInfo.new(1, Enum.EasingStyle.Linear))
tokenSheet:SetAttribute("QuadTransition", TweenInfo.new(0.25, Enum.EasingStyle.Quad))
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
-- 同时设置多个属性的过渡
frameRule:SetPropertyTransitions({
["BackgroundColor3"] = "$LinearTransition",
["BackgroundTransparency"] = "$QuadTransition",
})

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。