Using images
In this recipe, we will learn how to add an image to a view, use an already existing UIImage, put an image in a frame, and use modifiers to present beautiful images. The images in this section were obtained from https://unsplash.com/. Special thanks to jf-brou, Kieran White, and Camilo Fierro.
Getting ready
Create a new SwiftUI project named ImageApp
.
How to do it…
- Replace the initial
Text
view with aVstack
. - Download the project images from the GitHub link at https://github.com/PacktPublishing/SwiftUI-Cookbook/tree/master/Chapter01%20-%20Using%20the%20basic%20SwiftUI%20Views%20and%20Controls/03%20-%20Using%20Images
- Drag and drop the downloaded images for this recipe into the project's
Assets.xcassets
folder, as shown in the following screenshot: - Add an
Image
view toVStack
:Image("dogs1")
Observe the result in the canvas preview.
- Add a
.resizable()
modifier to the image...