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.
Create a new SwiftUI project named
How to do it…
- Replace the initial
Textview with a
- 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.xcassetsfolder, as shown in the following screenshot:
- Add an
Observe the result in the canvas preview.
- Add a
.resizable()modifier to the image...