Creating HeaderView with an info button
Let’s continue building out the UI and add a header title, which will be the name of our app. We can create this header in a separate file so we can keep our ContentView
clutter free.
The purpose of HeaderView
is twofold – to set the title of the app, and to add an info
button that opens a user settings page.
Press Command + N, choose a SwiftUI View file, and call it HeaderView
. Then, add a Binding
property in the HeaderView
struct:
@Binding var showSettings: Bool Now let's update the Previews struct to satisfy Xcode and so we can build cleanly again: HeaderView(showSettings: .constant(false)) .previewLayout(.fixed(width: 375, height: 80))
Next, add the following code inside the body
property:
ZStack { Image("title").resizable() ...