Structure

Image

A view that displays an image.

Declaration 宣言

@frozen struct Image

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

An image of a water wheel and its adjoining building, resized to fit the

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

Resizing Images

Specifying Rendering Behavior

Comparing Images 画像を比較する

Relationships 関係

Conforms To 次に準拠

See Also 参照

Image Fundamentals