Lớp công cụ
StyleRule
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Phương Pháp
GetDefaultPropertyTransition():Variant |
GetProperty(name: string):Variant |
SetDefaultPropertyTransition(transitionParams: Variant):() |
SetProperties(styleProperties: Dictionary):() |
SetProperty(name: string,value: Variant):() |
SetPropertyTransition(property: string,transitionParams: Variant):() |
SetPropertyTransitions(properties: Dictionary):() |
Tài Liệu Tham Khảo API
Thuộc Tính
Selector
Mẫu mã
Trình chọn lớp 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 rule = Instance.new("StyleRule")
rule.Parent = coreSheet
-- Trình chọn lớp
rule.Selector = "TextButton"
-- Đặt thuộc tính quy tắc
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 = "Menu Chính"
button.Parent = screenGuiTrình chọn thẻ 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
-- Trình chọn thẻ
rule.Selector = ".ButtonPrimary"
-- Đặt thuộc tính quy tắc
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 = "Thực đơn chính"
button.Parent = screenGui
-- Áp dụng thẻ cho nút
CollectionService:AddTag(button, "ButtonPrimary")Bộ Chọn Bộ Điều Chỉnh 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
-- Bộ chọn thành phần UI
rule.Selector = "Frame.RoundedCorner20::UICorner"
-- Đặt thuộc tính quy tắc
rule:SetProperty("CornerRadius", UDim.new(0, 20))
-- Tạo khung
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0.4, 0, 0.2, 0)
frame.Parent = screenGui
-- Áp dụng nhãn cho khung
CollectionService:AddTag(frame, "RoundedCorner20")Trình chọn truy vấn kiểu 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
-- Khai báo các trình chọn truy vấn kiểu
smallRule.Selector = "@Small"
mediumRule.Selector = "@Medium"
-- Thiết lập thuộc tính quy tắc
smallRule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("FF0099"),
["Text"] = "Thùng chứa Nhỏ",
["TextColor3"] = Color3.fromHex("E1E1E1"),
["TextSize"] = 12,
})
mediumRule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("F0F0F0"),
["Text"] = "Thùng chứa Trung Bình",
["TextColor3"] = Color3.fromHex("0022FC"),
["TextSize"] = 24,
})
local button = Instance.new("TextButton")
button.Text = "Menu Chính"
button.Parent = screenGui
button.Size = UDim2.fromScale(0.5, 0.2)
-- Tạo các truy vấn kiểu với tên phù hợp với các trình chọn quy tắc kiểu
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),
})Phương Pháp
GetDefaultPropertyTransition
StyleRule:GetDefaultPropertyTransition():Variant
Lợi Nhuận
Variant
GetPropertyTransitions
Lợi Nhuận
Mẫu mã
GetPropertyTransitions()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- Lấy tham chiếu đến quy tắc kiểu
local frameRule = coreSheet.Frame
-- Đặt một số chuyển tiếp
frameRule:SetPropertyTransition("BackgroundColor3", TweenInfo.new(1, Enum.EasingStyle.Linear))
frameRule:SetPropertyTransition("BackgroundTransparency", "$DefaultTransition")
local transitions = frameRule:GetPropertyTransitions()
print(transitions)SetDefaultPropertyTransition
StyleRule:SetDefaultPropertyTransition(transitionParams:Variant):()
Tham Số
transitionParams:Variant |
Lợi Nhuận
()
SetProperties
SetProperty
SetPropertyTransition
Tham Số
transitionParams:Variant |
Lợi Nhuận
()
Mẫu mã
SetPropertyTransition()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- Lấy tham chiếu đến quy tắc kiểu
local frameRule = coreSheet.Frame
-- Đặt chuyển tiếp 1 giây với Linear trên BackgroundColor3
frameRule:SetPropertyTransition("BackgroundColor3", TweenInfo.new(
1, -- Thời gian
Enum.EasingStyle.Linear -- EasingStyle
))
-- Xóa chuyển tiếp
frameRule:SetPropertyTransition("BackgroundColor3", nil)SetPropertyTransition() Sử dụng Tokens
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")
-- Đặt tokens (thuộc tính) trên bảng tokens
tokensSheet:SetAttribute("LinearTransition", TweenInfo.new(1, Enum.EasingStyle.Linear))
-- Lấy tham chiếu đến quy tắc kiểu
local frameRule = coreSheet.Frame
frameRule:SetPropertyTransition("BackgroundColor3", "$LinearTransition")SetPropertyTransitions
Tham Số
Lợi Nhuận
()
Mẫu mã
SetPropertyTransitions()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- Lấy tham chiếu đến quy tắc phong cách
local frameRule = coreSheet.Frame
-- Đặt chuyển tiếp cho hai thuộc tính cùng một lúc
frameRule:SetPropertyTransitions({
["BackgroundColor3"] = TweenInfo.new(1, Enum.EasingStyle.Linear),
["BackgroundTransparency"] = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
})
-- Xóa tất cả chuyển tiếp
frameRule:SetPropertyTransitions({})SetPropertyTransitions() Sử dụng Mã Thông Báo
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
local tokenSheet = ReplicatedStorage:FindFirstChild("Tokens")
-- Đặt mã thông báo (thuộc tính) trên bảng mã thông báo
tokenSheet:SetAttribute("LinearTransition", TweenInfo.new(1, Enum.EasingStyle.Linear))
tokenSheet:SetAttribute("QuadTransition", TweenInfo.new(0.25, Enum.EasingStyle.Quad))
-- Lấy tham chiếu đến quy tắc kiểu
local frameRule = coreSheet.Frame
-- Đặt chuyển tiếp cho nhiều thuộc tính cùng một lúc
frameRule:SetPropertyTransitions({
["BackgroundColor3"] = "$LinearTransition",
["BackgroundTransparency"] = "$QuadTransition",
})