一个 UIScale 对象简单包含用于乘以父 UI 元素的 GuiBase2d.AbsoluteSize 的数字。这个数字被存储在 UIScale.Scale 中。
代码示例
This code sample creates some images of a lock and scales them using UIScale. It lays them out using a UIListLayout.
UI Scale Demo
-- Lay out the images in a list
Instance.new("UIListLayout", script.Parent).SortOrder = Enum.SortOrder.LayoutOrder
-- Create some images of varying sizes using UIScale objects
for size = 0.2, 1.5, 0.2 do
local image = Instance.new("ImageLabel")
image.Image = "rbxassetid://284402752" -- an image of a Lock
image.Parent = script.Parent
image.Size = UDim2.new(0, 100, 0, 100)
-- Scale the image by adding a UIScale with the size
-- Note: this is a shorthand since we don't need a reference to the UIScale
Instance.new("UIScale", image).Scale = size
end
概要
属性
Scale
缩放属性决定了用于父级 UI 元素的 GuiBase2d.AbsoluteSize 上的倍率。当设置为 0.5 时,0、200、0、50 的绝对尺寸变为 0、100、0、25。同样,当设置为 2 时,这样的绝对尺寸将变为 0、400、0、100。
代码示例
This code sample creates some images of a lock and scales them using UIScale. It lays them out using a UIListLayout.
UI Scale Demo
-- Lay out the images in a list
Instance.new("UIListLayout", script.Parent).SortOrder = Enum.SortOrder.LayoutOrder
-- Create some images of varying sizes using UIScale objects
for size = 0.2, 1.5, 0.2 do
local image = Instance.new("ImageLabel")
image.Image = "rbxassetid://284402752" -- an image of a Lock
image.Parent = script.Parent
image.Size = UDim2.new(0, 100, 0, 100)
-- Scale the image by adding a UIScale with the size
-- Note: this is a shorthand since we don't need a reference to the UIScale
Instance.new("UIScale", image).Scale = size
end