学习
引擎类
ImageButton

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



API 参考
属性
HoverImage
读取并联
功能: UI
ImageButton.HoverImage:ContentId

HoverImageContent
读取并联
功能: UI
ImageButton.HoverImageContent:Content

Image
读取并联
功能: UI
ImageButton.Image:ContentId
代码示例
图像悬停锁定
local imageLabel = script.Parent
-- 这个示例中的图像是 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- 解锁的锁 (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- 深绿色
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- 锁定的锁 (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- 深红色
end
-- 连接事件;我们的默认状态是锁定
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()

ImageColor3
读取并联
功能: UI
ImageButton.ImageColor3:Color3
代码示例
图像悬停锁定
local imageLabel = script.Parent
-- 这个示例中的图像是 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- 解锁的锁 (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- 深绿色
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- 锁定的锁 (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- 深红色
end
-- 连接事件;我们的默认状态是锁定
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()

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

ImageRectOffset
读取并联
功能: UI
ImageButton.ImageRectOffset:Vector2
代码示例
使用精灵表的图像动画
-- 将此放置在大小为 256x256 的 ImageLabel/ImageButton 中
local imageLabel = script.Parent
-- 以下图像大小为 1024x1024,包含 12 帧(256x256)
-- 这些帧播放一个男人出拳的动画
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- 要显示的帧的顺序(从左到右,然后从上到下)
local frames = {
Vector2.new(0, 0),
Vector2.new(1, 0),
Vector2.new(2, 0),
Vector2.new(3, 0),
Vector2.new(0, 1),
Vector2.new(1, 1),
Vector2.new(2, 1),
Vector2.new(3, 1),
Vector2.new(0, 2),
Vector2.new(1, 2),
Vector2.new(2, 2),
Vector2.new(3, 2),
}
-- 在循环中逐帧动画
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end

ImageRectSize
读取并联
功能: UI
ImageButton.ImageRectSize:Vector2
代码示例
使用精灵表的图像动画
-- 将此放置在大小为 256x256 的 ImageLabel/ImageButton 中
local imageLabel = script.Parent
-- 以下图像大小为 1024x1024,包含 12 帧(256x256)
-- 这些帧播放一个男人出拳的动画
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- 要显示的帧的顺序(从左到右,然后从上到下)
local frames = {
Vector2.new(0, 0),
Vector2.new(1, 0),
Vector2.new(2, 0),
Vector2.new(3, 0),
Vector2.new(0, 1),
Vector2.new(1, 1),
Vector2.new(2, 1),
Vector2.new(3, 1),
Vector2.new(0, 2),
Vector2.new(1, 2),
Vector2.new(2, 2),
Vector2.new(3, 2),
}
-- 在循环中逐帧动画
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end

ImageTransparency
读取并联
功能: UI
ImageButton.ImageTransparency:number

IsLoaded
只读
未复制
读取并联
功能: UI
ImageButton.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))

PressedImage
读取并联
功能: UI
ImageButton.PressedImage:ContentId

PressedImageContent
读取并联
功能: UI
ImageButton.PressedImageContent:Content

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

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

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

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

TileSize
读取并联
功能: UI
ImageButton.TileSize:UDim2

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