ImageLabel

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

ImageLabel 會渲染一個長方形,像 Frame 一樣,但有圖像素材。顯示圖像可以通過 ImageColor3 和 1>Class.ImageLabel.ImageTransparency|

高級 ImageLabel 使用包括:

概要

屬性

屬性 繼承自 GuiObject屬性 繼承自 GuiBase2d

方法

方法 繼承自 GuiObject

活動

活動 繼承自 GuiObject活動 繼承自 GuiBase2d

屬性

Image

ContentId
平行讀取

此屬性是內容類型屬性,該屬性應該包含 Roblox 上傳的裝飾或圖像的資產 ID。它與 Decal.Texture 有關於從 Roblox 載入圖像的方式。 渲染圖像可以使用 ImageColor3 和 Class.ImageLabel.ImageTrans

ImageColor3

平行讀取

ImageColor3 屬性決定圖像的顏色化方式。當設為白色時,沒有顏色化發生。此屬性對於重用圖像資產非常有用;如果源圖像為完全白色並且具有透明度,您可以使用此屬性來設置整個圖像的顏色。

ImageContent

隱藏
平行讀取

此屬性應該包含一個 資產網址 或一個引用 EditableImage 對物件。

資產網址可以參照 Roblox 上傳的裝飾或圖像。它與 Decal.Texture 有關於載入圖像的方式。

渲染圖像將使用 ImageButton.ImageColor3 來上色。 您可以使用調整 ImageButton.ScaleType 屬性來調整圖像的大小、縮放和平移,以及 9 個點。

ImageRectOffset

平行讀取

允許在 ImageRectSize 與圖像的部分顯示。這個屬性決定圖像區域的 pixel Offset (從上方左邊) 。

ImageRectSize

平行讀取

允許在 ImageRectOffset 與圖像的部分顯示。這個屬性將圖像區域的像素尺寸設置為 0 。如果兩個尺寸都設置為 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 時,圖像會平滑畫面上大小超過其尺寸的文字。當設為 枚勒編輯器模式.Pixelized|枚勒編輯器模式.Pixelized 時,圖像會保留像素邊緣的鋒利邊緣。

平行讀取

ScaleType 屬性決定在 UI 元素的相對尺寸與來源圖像的尺寸不同的情況下 ImageLabel.Image 的渲染方式。

預設值為 Enum.ScaleType.Stretch ,這會簡單伸展圖像尺寸,以正確滿足 UI 元素的空間。雖然透明像素在上傳到 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 為預設值。這個屬性只有在 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

方法

活動