The UIImage class represents an image object that can be loaded, encoded, converted, and displayed.
It supports creating images from file paths, binary data, or Base64 strings and provides multiple format conversion methods (PNG/JPEG).
UIImage can be displayed directly in an Image component or used with the Data class for storage, uploading, or encryption.
UIImage is the core class for handling images in the scripting environment. It is commonly used for:
width: numberThe width of the image in pixels.
height: numberThe height of the image in pixels.
scale: numberThe scale factor of the image, usually 1 or 2 for Retina displays.
imageOrientation: stringThe orientation of the image. Possible values:
"up""down""left""right""upMirrored""downMirrored""leftMirrored""rightMirrored""unknown"isSymbolImage: booleanIndicates whether the image is an SF Symbol image.
renderingMode: "automatic" | "alwaysOriginal" | "alwaysTemplate" | "unknown"The rendering mode of the image:
automatic: Automatically determined by the systemalwaysOriginal: Display the image in its original coloralwaysTemplate: Render the image as a template (can be tinted)resizingMode: "tile" | "stretch" | "unknown"The resizing mode of the image:
"tile": The image is tiled to fill the area"stretch": The image is stretched to fitcapInsets: { top: number, left: number, bottom: number, right: number }The cap insets that define the stretchable area of the image.
flipsForRightToLeftLayoutDirection: booleanIndicates whether the image automatically flips in right-to-left (RTL) layout directions.
preparingThumbnail(size: Size): UIImage | nullCreates a thumbnail with the specified size.
Parameters:
size.width: Width of the thumbnailsize.height: Height of the thumbnailReturns:
A new UIImage instance, or null if creation fails.
Example:
withBaselineOffset(offset: number): UIImageReturns a new image with the specified baseline offset, it is useful for aligning text to the bottom of an image.
withHorizontallyFlippedOrientation(): UIImageReturns a new image with horizontally flipped orientation.
withTintColor(color: string, renderingMode?: "automatic" | "alwaysOriginal" | "alwaysTemplate"): UIImage | nullApplies a tint color to the image using the specified rendering mode.
Parameters:
color: The tint color as a string, e.g. "#ffcc00" or "rgb(255,128,0)"renderingMode: The rendering mode to use. Defaults to "automatic"Example:
withRenderingMode(renderingMode: "automatic" | "alwaysOriginal" | "alwaysTemplate"): UIImage | nullReturns a new version of the image using the specified rendering mode.
resizableImage(capInsets, resizingMode?): UIImage | nullReturns a new version of the image with specified cap insets and resizing mode.
Parameters:
capInsets: { top, left, bottom, right }resizingMode: "tile" or "stretch" (default "tile")Example:
renderedInCircle(radius?: number | null, fitEntireImage?: boolean): UIImageReturns a new version of the image rendered as a circle, with optional radius and fit behavior.
Parameters:
radius (optional): The radius of the circle in points.
If not specified:
fitEntireImage is false, the circle uses the shortest dimension of the image.fitEntireImage is true, the circle uses the longest dimension of the image.fitEntireImage (optional): Whether to fit the entire image inside the circle.
true.false, the image fills the circular area and may be cropped.Returns:
UIImage instance representing the circular rendering.Example 1: Create a default circular avatar
Example 2: Specify radius and fit entire image
Example 3: Fill mode (may crop parts of the image)
renderedIn(size: { width: number, height: number }, source?: { position?: ..., size?: ... }): UIImage | nullReturns a new version of the image rendered with the specified size and optional source region.
Parameters:
size: { width: number, height: number } - The size of the rendered image.source: { position?: { x: number, y: number }, size?: { width: number, height: number } } - The source region of the image.Returns:
UIImage instance if rendering succeeds, or null if it fails.Example 1: Scale entire image into a rectangle
Example 2: Crop and render a specific region
applySymbolConfiguration(config: UIImageSymbolConfiguration | UIImageSymbolConfiguration[]): UIImage | nullReturns a new version of the image with the specified symbol configuration (UIImageSymbolConfiguration).
This method is primarily used to customize the appearance of SF Symbols images, including color, weight, size, rendering mode, and palette.
Parameters:
config: The symbol configuration to apply to the image.
UIImageSymbolConfiguration instance, orReturns:
UIImage instance representing the symbol with applied configuration, or null if the operation fails.Example 1: Display a symbol in multicolor
Example 2: Apply both scale and weight configurations
Example 3: Set hierarchical and palette colors
UIImageSymbolConfiguration is a class used to define appearance configurations for symbol images (SF Symbols).
Instances created with its static methods can be passed to applySymbolConfiguration() to modify how the symbol is rendered.
| Method | Description |
|---|---|
preferringMonochrome() |
Prefers monochrome rendering for the symbol. |
preferringMulticolor() |
Prefers multicolor rendering for the symbol. |
scale(value) |
Sets the scale of the symbol. Possible values: "default", "large", "medium", "small", "unspecified". |
weight(value) |
Sets the stroke weight of the symbol. Possible values: "ultraLight", "thin", "light", "regular", "medium", "semibold", "bold", "heavy", "black". |
pointSize(value) |
Sets the point size of the symbol. |
paletteColors(value) |
Sets a color palette (array of Color) for multicolor or layered symbols. |
hierarchicalColor(value) |
Applies a hierarchical color (used for layered shading effects). |
variableValueMode(value) |
Sets how variable-value symbols are displayed. Possible values: "automatic", "color", "draw". |
colorRenderingMode(value) |
Sets the color rendering mode. Possible values: "automatic", "flat", "gradient". |
locale(identifier) |
Sets the locale for localized symbol variants (e.g., "en", "zh-Hans"). |
Example: Combine multiple symbol configurations
toJPEGData(compressionQuality?: number): Data | nullConverts the image to JPEG data.
Parameters:
compressionQuality: A number between 0 and 1, default is 1.Returns:
A Data instance or null.
toPNGData(): Data | nullConverts the image to PNG data.
Returns a Data instance or null.
toJPEGBase64String(compressionQuality?: number): string | nullConverts the image to a Base64-encoded JPEG string.
toPNGBase64String(): string | nullConverts the image to a Base64-encoded PNG string.
UIImage.fromData(data: Data): UIImage | nullCreates an image from a Data instance containing PNG or JPEG data.
UIImage.fromFile(filePath: string): UIImage | nullCreates an image from a file path (supports PNG, JPG, JPEG).
UIImage.fromBase64String(base64String: string): UIImage | nullCreates an image from a Base64 string.
UIImage.fromSFSymbol(name: string): UIImage | nullCreates an image from a system SF Symbol.
Example:
UIImage.fromURL(url: string): Promise<UIImage | null>Creates an image from a URL.
Example:
UIImage can be displayed directly in the <Image> component.
Used for automatically switching images in light and dark mode.
UIImage is the core class for image manipulation in the Scripting environment. It provides:
<Image> component