Image

A view that displays an image.

ComponentiOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+Image in SwiftUI

Declaration

React
import { Image } from 'swiftui-react-native';
Swift
@frozen struct Image

Initializers

11 SwiftUI initializers back <Image>. The props you pass pick one.

React
<Image
  resource: string
/>
Swift
init(_ resource: ImageResource)
  • resource*string

Also takes the common view props: modifiers, style and testID.

Overview

Use an Image instance when you want to add images to your SwiftUI app. You can create images from many sources:

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")

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 Image.resizable(capInsets:resizingMode:) method scales the image to fit the current view. Then, the View.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 doc: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.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Relationships

Conforms to

  • CoreTransferable.Transferable
  • Swift.Copyable
  • Swift.Equatable
  • Swift.Escapable
  • Swift.Sendable
  • Swift.SendableMetatype
  • View

See also

More in Text and images.