Previewing a view on different devices
Xcode 15 allows us to preview our designs on multiple screen sizes and device types simultaneously, using the new device selector. In this recipe, we will create a simple app that displays an image and some text and preview it in multiple devices, without using any additional code.
Getting ready
Let’s create a SwiftUI app named PreviewOnDifferentDevices
.
How to do it…
We will add an image and some text to the ContentView
struct and then modify the preview to show the content on multiple devices. The steps are as follows:
- Download the
friendship.jpg
image from this chapter’s resources file at https://github.com/PacktPublishing/SwiftUI-Cookbook-3rd-Edition/blob/main/Resources/Chapter04/recipe3/friendship.jpg. - Drag and drop the downloaded image file into the
Assets
folder in Xcode. - Open the
ContentView.swift
file, and replace its content with the following code to display an image and some...