Selector 속성에 영향을 받는 인스턴스의 속성을 재정의하는 스타일 속성을 정의합니다.
요약
속성
StyleRule의 속성이 다른 StyleRules의 동일한 속성에 대해 어떻게 적용되는지 결정하는 숫자입니다.우선 순위가 높은 값은 낮은 값보다 우선합니다.
StyleRule가 영향을 미칠 인스턴스를 지정하는 문자열.
Selector 속성에서 오류를 표시하는 읽기 전용 문자열.
메서드
StyleRule의 속성을 설명하는 키-값 쌍의 사전을 반환합니다.
StyleRule에서 특정 속성의 값을 반환합니다.
한 번에 StyleRule의 여러 속성을 선언하고 설정할 수 있습니다.
관련된 배열 StyleRules 을 반환합니다.
규칙 배열에 새로운 StyleRule를 삽입합니다.
InsertStyleRule()와 비슷하지만 한 번에 여러 StyleRules를 선언하고 설정할 수 있습니다.
속성
Priority
StyleRule의 속성이 다른 StyleRules의 동일한 속성에 대해 어떻게 적용되는지 결정하는 숫자입니다.우선 순위가 높은 값은 낮은 값보다 우선합니다.예를 들어, 우선 순위가 StyleRule 인 10 가진 AnchorPoint 속성의
Selector
StyleRule가 영향을 미칠 인스턴스를 지정하는 문자열.이는 클래스 이름, 인스턴스 이름 및 계층 관계와 같은 특성에 맞게 선택자와 결합자를 혼합할 수 있습니다.
예를 들어, ".Container > ImageLabel.BlueOnHover:Hover" 효과적으로 스타일 규칙이 모든 ImageLabel 를 무시하고 태그된 인스턴스의 자식인 Container ( .Container > ImageLabel ) 의 모든 및 는 BlueOnHover ( .BlueOnHover ) 의 상태에 있습니다( **** ) 및 은 상태가 Enum.GuiState.Hover 입니다( :Hover ).
선택자
<th>설명</th><th>예시</th></tr></thead><tbody><tr><td><code>[클라스]</code></td><td><code>Class.GuiObject</code> 또는 <code>Class.UIComponent</code> 클래스의 인스턴스와 일치합니다.</td><td><code>"프레임"</code><code>"이미지 버튼"</code><code>"UICorner"</code></td></tr><tr><td><code>.[태그]</code></td><td><a href="/studio/properties#instance-tags">태그된</a> 인스턴스와 <code>Class.CollectionService</code> 태그로 태그가 지정된 인스턴스를 일치시킵니다.</td><td><code>".Container"</code><code>".BlueOnHover"</code></td></tr><tr><td><code>#[name]</code></td><td>특정 <code>Class.Instance.Name</code> 인스턴스의 일치 항목.</td><td><code>"#ModalFrame"</code><code>"#CloseButton"</code></td></tr><tr><td><code>상태: [state]</code></td><td>현재 <code>Enum.GuiState</code>에 있는 인스턴스와 일치합니다.</td><td><code>":호버"</code></td></tr></tbody>
선택자 |
---|
결합자
<th>설명</th><th>예시</th></tr></thead><tbody><tr><td><code>></code></td><td>이전 필터 일치 항목의 <b>직접 자식</b>인 인스턴스를 찾습니다.</td><td width="40%"><code>“프레임 > .인벤토리”</code></td></tr><tr><td><code>>></code></td><td>이전 필터 일치 항목의 후손인 인스턴스를 찾습니다. <b>descendants</b> of the previous filter matches.</td><td><code>“이미지 버튼 >> .BlueOnHover”</code></td></tr><tr><td><code>,</code></td><td>스타일 규칙에 대한 여러 독립적인 선택자 목록을 지정합니다.</td><td><code>“Frame.TagA, TextLabel.TagA”</code></td></tr><tr><td><code>::</code></td><td>이전 필터에서 일치하는 phantom <code>Class.UIComponent</code> 인스턴스를 생성하고 스타일 규칙의 속성을 적용합니다.</td><td><code>“프레임::UICorner”</code></td></tr></tbody>
결합기 |
---|
코드 샘플
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")
메서드
GetProperties
예를 들어 StyleRule의 속성을 설명하는 키-값 쌍의 사전을 반환합니다:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- 스타일 규칙에 대한 참조 받기local frameRule = coreSheet.Framelocal props = frameRule:GetProperties()print(props)--[[{["AnchorPoint"] = 0.5, 0,["BackgroundColor3"] = 1, 0, 0.25}]]
반환
키-값 쌍으로 설명되는 StyleRule의 속성을 설명하는 사전.
GetProperty
StyleRule에서 특정 속성의 값을 반환합니다.
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- 스타일 규칙에 대한 참조 받기local frameRule = coreSheet.Framelocal prop = frameRule:GetProperty("AnchorPoint")print(prop) --> 0.5, 0
매개 변수
속성의 문자열 이름, 예를 들어 "AnchorPoint" 또는 "BackgroundColor3".
반환
속성의 값.
SetProperties
SetProperty()와 비슷하지만 한 번에 StyleRule의 여러 속성을 선언하고 설정할 수 있습니다.각 할당은 영향을 받는 각 GuiObject 또는 UIComponent ( UICorner , UIGradient , 등)의 유효한 속성이어야 하며, 할당된 각 값은 속성의 값 유형과 일치해야 합니다(예: Vector2 에 대한 AnchorPoint 또는 Color3 에 대한 BackgroundColor3 등).
"AnchorPt" 또는 "BkColor"와 같은 유효하지 않은 속성 이름 할당 시도는 조용히 실패합니다. 또는 에 대한 유형 오류와 같이 또는 또는 에 대한 유형 오류도 발생하고 출력 창에 오류가 나타납니다.
StyleRule의 단일 속성을 설정하거나 업데이트하려면 참조하십시오 SetProperty() .
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- 스타일 규칙에 대한 참조 받기local frameRule = coreSheet.Frame-- 규칙 속성 설정frameRule:SetProperties({["AnchorPoint"] = Vector2.new(0.5, 0),["BackgroundColor3"] = Color3.new(1, 0, 0.25)})
토큰 을 속성 값으로 할당할 수 있는 프리픽스 $를 통해:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")-- 토큰 시트에서 토큰(특성) 설정tokensSheet:SetAttribute("TopCenterAnchor", Vector2.new(0.5, 0))tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))-- 스타일 규칙에 대한 참조 받기local frameRule = coreSheet.Frame-- 규칙 속성 설정frameRule:SetProperties({["AnchorPoint"] = "$TopCenterAnchor",["BackgroundColor3"] = "$MainBackgroundColor"})
매개 변수
설정할 속성을 정의하는 키-값 쌍 사전. Dictionary of key-value pairs defining the properties to set.
반환
SetProperty
새 속성(또는 기존 속성 수정)을 StyleRule에 설정합니다.name 매개 변수는 영향을 받는 GuiObject 또는 UIComponent (UICorner , UIGradient , 등)의 유효한 속성이어야 하며, 할당된 값은 속성의 값 유형과 일치해야 합니다(예: Vector2 에서 AnchorPoint 또는 Color3 에서 BackgroundColor3 등).
"AnchorPt" 또는 "BkColor"와 같은 유효하지 않은 속성 이름 할당 시도는 조용히 실패합니다. 또는 에 대한 유형 오류와 같이 또는 또는 에 대한 유형 오류도 발생하고 출력 창에 오류가 나타납니다.
한 번에 StyleRule 여러 속성을 설정하려면 SetProperties()를 참조하십시오.
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- 스타일 규칙에 대한 참조 받기local frameRule = coreSheet.Frame-- 규칙 속성 설정frameRule:SetProperty("BackgroundColor3", Color3.new(1, 0, 0.25))
토큰 을 속성 값으로 할당할 수 있는 프리픽스 $를 통해:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")-- 토큰 시트에서 새 토큰(특성) 설정tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))-- 스타일 규칙에 대한 참조 받기local frameRule = coreSheet.Frame-- 토큰을 값으로 사용하도록 규칙 속성 설정frameRule:SetProperty("BackgroundColor3, "$MainBackgroundColor")
매개 변수
예를 들어 "BackgroundColor3"와 같이 설정할 속성 이름.
예를 들어 Color3.new(1, 0, 0.25) 설정할 속성 값.