学习
引擎类
ImageLabel

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



API 参考
属性
Image
读取并联
功能: UI
ImageLabel.Image:ContentId

ImageColor3
读取并联
功能: UI
ImageLabel.ImageColor3:Color3

ImageContent
读取并联
功能: UI
ImageLabel.ImageContent:Content

ImageRectOffset
读取并联
功能: UI
ImageLabel.ImageRectOffset:Vector2

ImageRectSize
读取并联
功能: UI
ImageLabel.ImageRectSize:Vector2

ImageTransparency
读取并联
功能: UI
ImageLabel.ImageTransparency:number
代码示例
振荡图像透明度
local RunService = game:GetService("RunService")
local imageLabel = script.Parent
local function onRenderStep()
-- 使用正弦波在0到1之间振荡图像透明度
imageLabel.ImageTransparency = math.sin(workspace.DistributedGameTime * math.pi) * 0.5 + 0.5
end
RunService.RenderStepped:Connect(onRenderStep)

IsLoaded
只读
未复制
读取并联
功能: UI
ImageLabel.IsLoaded:boolean
代码示例
图片加载时间
local imageLabel = script.Parent
local startTime = workspace.DistributedGameTime
-- 等待图片加载
while not imageLabel.IsLoaded do
task.wait()
end
-- 测量并显示加载所需的时间
local deltaTime = workspace.DistributedGameTime - startTime
print(("图片加载时间为 %.3f 秒"):format(deltaTime))

ResampleMode
读取并联
功能: UI
ImageLabel.ResampleMode:Enum.ResamplerMode

ScaleType
读取并联
功能: UI
ImageLabel.ScaleType:Enum.ScaleType

SliceCenter
读取并联
功能: UI
ImageLabel.SliceCenter:Rect

SliceScale
读取并联
功能: UI
ImageLabel.SliceScale:number

TileSize
读取并联
功能: UI
ImageLabel.TileSize:UDim2
代码示例
图片缩放类型演示
local imageLabel = script.Parent
-- 将源图像设置为 64x64 的挂锁
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- 白色
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- 黑色
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
-- 拉伸仅是将源图像拉伸以适应
-- UI 元素的空间
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- 平铺会多次渲染源图像
-- 足够填充 UI 元素的空间
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- 切片会将图像转换为九切片 UI。
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end

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