Image
The Image component allows you to display images from various sources, such as system symbols, network URLs, local files, or UIImage objects. It supports dynamic image sources that change based on light or dark color schemes. Additionally, several view modifiers are available to customize the behavior and appearance of the Image component.
Type Definitions
ImageResizable
Defines how the image should be resized:
-
boolean:true: Enables default resizing.false: Disables resizing.
-
object:-
capInsets(optional):EdgeInsetsDefines insets for image stretching to control which parts of the image stretch and which remain fixed. -
resizingMode(optional):ImageResizingModeSpecifies the resizing mode, such as scaling or tiling.
-
ImageScale
Specifies relative image sizes available within the view:
'large': Renders the image at a large size.'medium': Renders the image at a medium size.'small': Renders the image at a small size.
DynamicImageSource<T>
Defines a dynamic source that changes based on the system color scheme:
Used for adapting the image resource for light/dark modes. Supported in:
imageUrl(network images)filePath(local file images)image(UIImageobjects)
Source Props
SystemImageProps
-
systemName(string, required) The name of a system-provided symbol. Refer to the SF Symbols library or use the SF Symbols Browser app to browse available symbol names. -
variableValue(number, optional) A value between0.0and1.0for customizing the appearance of a variable symbol. (Has no effect for symbols that do not support variable values.) -
resizable(ImageResizable, optional) Configures how the image is resized to fit its allocated space.
NetworkImageProps
-
imageUrl(string | DynamicImageSource<string>, required) The URL of the image to load. Supports dynamic sources viaDynamicImageSource. -
placeholder(VirtualNode, optional) A view displayed while the image is loading. -
resizable(ImageResizable, optional) Configures how the image is resized to fit its allocated space.
FileImageProps
-
filePath(string | DynamicImageSource<string>, required) The path to the local image file. Supports dynamic sources viaDynamicImageSource. -
resizable(ImageResizable, optional) Configures how the image is resized to fit its allocated space.
UIImageProps
-
image(UIImage | DynamicImageSource<UIImage>, required) AUIImageobject to display. Supports dynamic sources viaDynamicImageSource. -
resizable(ImageResizable, optional) Configures how the image is resized to fit its allocated space.
CommonViewProps
Modifiers applicable to the Image component and other views:
-
scaleToFit(boolean, optional) Scales the view to fit its parent container. -
scaleToFill(boolean, optional) Scales the view to fill its parent container. -
aspectRatio(object, optional) Configures the view's aspect ratio:value(number or null, optional): The width-to-height ratio. Ifnull, maintains the current aspect ratio.contentMode(ContentMode, required): Determines whether the content fits or fills its parent.
-
imageScale(ImageScale, optional) Adjusts the size of images within the view. Options:'large','medium','small'. -
foregroundStyle(ShapeStyle or DynamicShapeStyle or object, optional) Configures the view's foreground elements:primary: Style for the primary foreground elements.secondary: Style for secondary elements.tertiary(optional): Style for tertiary elements.
Rendering Behavior (ImageRenderingBehaviorProps)
Usage Examples
- Dynamic Network Image Based on Color Scheme
- Dynamic Local File Image
- Dynamic UIImage Object
- System Symbol with Aspect Ratio and Scaling
Notes
- Use
DynamicImageSourceto adapt images for light/dark mode with minimal logic. - Combine view modifiers like
scaleToFit,scaleToFill, andaspectRatioto achieve precise layout configurations. - Use the
foregroundStyleproperty for detailed styling of icons or symbols. - Ensure URLs and file paths provided for dynamic image sources are valid and accessible.
