SwiftUI For Dummies. Wei-Meng Lee

Чтение книги онлайн.

Читать онлайн книгу SwiftUI For Dummies - Wei-Meng Lee страница 12

SwiftUI For Dummies - Wei-Meng Lee

Скачать книгу

project that you’ve created.

      Automatically previewing your user interface using the canvas

Dismissing the Inspector window.

      FIGURE 1-8: Dismissing the Inspector window.

      

If you don’t see the canvas, you can bring it up again through the Editor ⇒ Canvas menu.

      

If you don’t see the Resume button, make sure you’re running macOS Catalina (10.15) or later.

The canvas allows you to preview your application without deploying it on the iPhone Simulator or a real device.

      FIGURE 1-9: The canvas allows you to preview your application without deploying it on the iPhone Simulator or a real device.

Previewing your app on the canvas.

      FIGURE 1-10: Previewing your app on the canvas.

Modifying the ContentView.swift file.

      FIGURE 1-11: Modifying the ContentView.swift file.

The preview is updated to reflect the changes in the code.

      FIGURE 1-12: The preview is updated to reflect the changes in the code.

       Text("Submit")

       .padding(EdgeInsets(

       top: 10, leading: 10,

       bottom: 10, trailing: 10))

       .background(Color.blue)

The automatic update feature of preview doesn't always work. There are times where you have to click Try Again to rebuild the preview (see Figure 1-13).

Occasionally you have to click the Try Again button to update the preview.

      FIGURE 1-13: Occasionally you have to click the Try Again button to update the preview.

      Working with Live Preview

Clicking the Live Preview button allows you to run your application directly on the canvas.

      FIGURE 1-14: Clicking the Live Preview button allows you to run your application directly on the canvas.

Testing your application in Live Preview mode.

      FIGURE 1-15: Testing your application in Live Preview mode.

      Generating different previews

      Notice this block of code at the bottom of ContentView.swift?

       struct ContentView_Previews: PreviewProvider {

       static var previews: some View {

       ContentView()

       }

       }

Previewing the UI on two iOS devices — the latest iPhone and an iPhone SE.

      FIGURE 1-16: Previewing the UI on two iOS devices — the latest iPhone and an iPhone SE.

       struct ContentView_Previews: PreviewProvider {

      

Скачать книгу