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/, so special thanks to jf-brou, Kieran White, and Camilo Fierro.
Getting ready
Let's start by creating a new SwiftUI project called ImageApp
.
How to do it…
Let's add some images to our SwiftUI project and introduce the modifiers used to style them. The steps are given here:
- Replace the initial
Text
view with aVStack
. - Download the project images from the GitHub link at https://github.com/PacktPublishing/SwiftUI-Cookbook-2nd-Edition/tree/main/Resources/Chapter01/recipe3.
- Drag and drop the downloaded images for this recipe into the project's
Assets.xcassets
(or Assets) folder, as shown in the following screenshot: - Add an
Image
view toVStack...