Image
A view that displays an image.
Declaration
@frozen struct ImageMentioned in
Overview
Use an Image instance when you want to add images to your SwiftUI app. You can create images from many sources:
Image files in your app’s asset library or bundle. Supported types include PNG, JPEG, HEIC, and more.
Instances of platform-specific image types, like UIImage and NSImage.
A bitmap stored in a Core Graphics CGImage instance.
System graphics from the SF Symbols set.
The following example shows how to load an image from the app’s asset library or bundle and scale it to fit within its container:
Image("Landscape_4")
.resizable()
.aspectRatio(contentMode: .fit)
Text("Water wheel")[Image]
You can use methods on the Image type as well as standard view modifiers to adjust the size of the image to fit your app’s interface. Here, the Image type’s resizable(capInsets:resizingMode:) method scales the image to fit the current view. Then, the aspectRatio(_:contentMode:) view modifier adjusts this resizing behavior to maintain the image’s original aspect ratio, rather than scaling the x- and y-axes independently to fill all four sides of the view. The article Fitting images into available space shows how to apply scaling, clipping, and tiling to Image instances of different sizes.
An Image is a late-binding token; the system resolves its actual value only when it’s about to use the image in an environment.
Making images accessible
To use an image as a control, use one of the initializers that takes a label parameter. This allows the system’s accessibility frameworks to use the label as the name of the control for users who use features like VoiceOver. For images that are only present for aesthetic reasons, use an initializer with the decorative parameter; the accessibility systems ignore these images.
Topics
Creating an image
Creating an image for use as a control
Creating an image for decorative use
Creating a system symbol image
Creating an image from another image
Creating an image from drawing instructions
Resizing images
Specifying rendering behavior
antialiased(_:)symbolRenderingMode(_:)renderingMode(_:)interpolation(_:)Image.TemplateRenderingModeImage.Interpolation