init(String, bundle: Bundle?)
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
andNSImage
.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")
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(cap
method scales the image to fit the current view. Then, the aspect
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.