Closed1

NavigationView

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            MasterView()
        }
    }
}

struct MasterView: View {
    @State var showingSubView0 = true
    @State var showingSubView1 = false
    @State var showingSubView2 = false
    var body: some View {
        VStack {
//                NavigationLink(destination: SubView1()) {
//                    Text("Navigate1")
//                }
//                NavigationLink(destination: SubView2()) {
//                    Text("Navigate2")
//                }
            NavigationLink(destination: SubView0(), isActive: $showingSubView0) {
                EmptyView()
            }
            NavigationLink(destination: SubView1(), isActive: $showingSubView1) {
                EmptyView()
            }
            NavigationLink(destination: SubView2(), isActive: $showingSubView2) {
                EmptyView()
            }
            Button("Navigate1") {
                showingSubView1.toggle()
            }
            Button("Navigate2") {
                showingSubView2.toggle()
            }
        }
        .navigationTitle("Title")
        .navigationBarTitleDisplayMode(.inline)
        .toolbar {
            ToolbarItem(placement: .navigationBarTrailing) {
                Image(systemName: "magnifyingglass")
            }
        }
    }
}

struct SubView0: View {
    var body: some View {
        Text("SubView0")
            .navigationTitle("SubView0")
            .navigationBarTitleDisplayMode(.inline)
    }
}

struct SubView1: View {
    var body: some View {
        Text("SubView1")
            .navigationTitle("SubView1")
            .navigationBarTitleDisplayMode(.inline)
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    Image(systemName: "person")
                }
            }
    }
}

struct SubView2: View {
    var body: some View {
        Text("SubView2")
            .navigationTitle("SubView2")
            .navigationBarTitleDisplayMode(.inline)
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    Image(systemName: "person.fill")
                }
            }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

このスクラップは2021/04/09にクローズされました
ログインするとコメントできます