ImageLabel

显示已弃用

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

一个 ImageLabel 会渲染一个长方形,像 Frame 一样,通过图像素材。显示图像可以通过 ImageColor3 和 1> Class.ImageLabel.ImageTransparency

高级ImageLabel 使用包括:

概要

属性

继承自GuiObject属性继承自GuiBase2d属性

方法

继承自GuiObject方法

活动

继承自GuiObject活动继承自GuiBase2d活动

属性

Image

ContentId
读取并联

Image 属性是一个内容类型属性,该内容 ID 是由 Roblox 上传的图像或贴纸的资产。它与 Decal.Texture 有关于从 Roblox 加载图像的方面。 渲染图像可以使用 ImageColor3

ImageColor3

读取并联

ImageColor3 属性确定图像的颜色化方式。设置为“白色”,就不会进行颜色化。此属性对于重用图像资产非常有用;如果源图像是完全白色且透明,你可以使用此属性来设置整个图像的颜色。

ImageContent

隐藏
读取并联

ImageRectOffset

读取并联

允许在 ImageRectSize 与图像的部分显示。 此属性确定显示区域的像素 Offset (从左上角) 。

ImageRectSize

读取并联

允许在 ImageRectOffset 与图像的部分显示。 此属性决定显示的图像区域的像素大小。如果两个尺寸都设置为 0,整个图像将在显示。

ImageTransparency

读取并联

ImageTransparency 确定 UI 元素的渲染图像的 alpha 值。一个值为 0 是完全不透明的,一个值为 1 是完全透明的(隐形)。

代码示例

This code sample oscillates the ImageTransparency of an ImageLabel/ImageButton from 0 to 1 using a sine wave.

Oscillate ImageTransparency

local RunService = game:GetService("RunService")
local imageLabel = script.Parent
local function onRenderStep()
-- Oscillate ImageTransparency from 0 to 1 using a sine wave
imageLabel.ImageTransparency = math.sin(workspace.DistributedGameTime * math.pi) * 0.5 + 0.5
end
RunService.RenderStepped:Connect(onRenderStep)

IsLoaded

只读
未复制
读取并联

IsLoaded 属性表示 ImageLabel.Image 属性是否已从 Roblox 完成加载。 图像由 moderation 拒绝的图像永远不会加载。

代码示例

This code sample measures how long an ImageLabel or ImageButton takes to load an image. If the image was already loaded, this will be 0.

Image Load Time

local imageLabel = script.Parent
local startTime = workspace.DistributedGameTime
-- Wait for the image to load
while not imageLabel.IsLoaded do
task.wait()
end
-- Measure and display how long it took to load
local deltaTime = workspace.DistributedGameTime - startTime
print(("Image loaded in %.3f seconds"):format(deltaTime))

ResampleMode

读取并联

确定图像在缩放时的外观。默认情况下,图像在显示屏幕大小或更小于其内容记录时会平滑其纹理。当设置为 Enum.ResamplerMode.Pixelated 时,图像保留像素边缘的锋利边缘。

读取并联

ScaleType 属性决定ImageLabel.Image 的尺寸在 UI 元素的绝对尺寸与源图像的尺寸之间的显示方式。

默认情况下,此属性是 Enum.ScaleType.Stretch ,它将简单地伸展图像尺寸以确保它与 Roblox 元素的空间完全匹配。随着透明像素在上传到 Roblox 时设置为黑色,因此透明图像应该使用 alpha 渐变来避免在缩放图像周围形成黑色轮廓。

对于 Enum.ScaleType.SliceSliceCenter 属性将在 属性 窗口中显示。 此为九个滑块 UI : 缩放时,角落将保持源图像大小。 边缘的图像将拓展到图像的宽度/高度。 最后,中心部分的图像将拓展

最后,对于 Enum.ScaleType.TileTileSize 属性将在 属性窗口 中显示。 这是为了用于地砖图像,其中每个图像块的大小由 1> Class.ImageLabel.TileSize|TileSize1> 属性决定。

SliceCenter

读取并联

SliceCenter 属性设置 9 个切割的图像的切割边界,当 ScaleType 设置为 Enum.ScaleType.Slice 时。 请注意,此属性仅在此条件下的 1>属性1> 窗口中可见。

了解更多关于 9 片图像的信息,请参阅 UI 9 Slice Design

SliceScale

读取并联

按照指定比例缩放 9 个边。这意味着边缘 9 侧将以新版本的材质上升为您所上传的版本的大小。默认为 1.0

还请参阅ScaleTypeSliceCenterSliceScale

TileSize

读取并联

TileSize 设置了 ImageLabel 的地砖大小,为默认值 8 。 地砖始于图像的左上角。 此属性仅在 0> Class.ImageLabel.ScaleType|

代码示例

This code sample demonstrates the different ScaleType options - Stretch, Tile and Slice. It does this by resizing an ImageLabel/ImageButton in a circle.

Image ScaleType Demo

local imageLabel = script.Parent
-- Set the source image to be a 64x64 padlock
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- White
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- Black
local function resizeInACircle()
for theta = 0, 2, 0.02 do
imageLabel.Size = UDim2.new(
0,
100 + math.cos(theta * 2 * math.pi) * 50,
0,
100 + math.sin(theta * 2 * math.pi) * 50
)
task.wait()
end
end
while true do
-- Stretch simply stretches the source image to fit
-- the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- Tile will render the source image multiple times
-- enough to fill the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- Slice will turn the image into a nine-slice UI.
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end

方法

活动