0

I am writing a simple watchOS app using SwiftUI but I am having issues to proper layout it. This is the code:


struct ContentView: View {
    var body: some View {
        VStack(spacing: 0) {
            HeaderView()
            NavigationView {
                ScrollView {
                    NavigationLink(destination: View1()) {
                        Text("View 1")
                    }
                    NavigationLink(destination: View2()) {
                        Text("View 2")
                    }
                    NavigationLink(destination: View2()) {
                        Text("View 3")
                    }
                    NavigationLink(destination: View2()) {
                        Text("View 4")
                    }
                }
            }
            .navigationBarTitleDisplayMode(.inline)
        }
    }
}

struct HeaderView: View {
    var body: some View {
        VStack() {
            Text("Header")
        }
        .frame(maxWidth: .infinity)
        .background(Color.red)
    }
}
struct View2: View {
    var body: some View {
        VStack {
            Text("View 2 Content")
        }
        .navigationTitle("View 2")
        .toolbar {
            ToolbarItem(placement: .primaryAction) {
                Button("+") {
                }
            }
        }
    }
}

Issues:

  1. I cannot rid of this unused space

enter image description here

  1. No matter what the "+" button shows up below the toolbar. I would like to have it in the shown position

enter image description here

Timmy
  • 4,098
  • 2
  • 14
  • 34
Fab
  • 1,468
  • 1
  • 16
  • 37

0 Answers0