2

I have created one sidebar with NavigationView, which by default appends to the left of the landscape view of application. However I wanted to have another on the right side.

NavigationView {
  List {
    Label("Pencil", systemImage: "pencil")
    Label("Paint", systemImage: "paintbrush.fill")
    Label("Erase", systemImage: "quote.opening")
      Label("Cutter", systemImage: "scissors")
      Label("Eyedropper", systemImage: "eyedropper.halffull")
      Label("Draw Line", systemImage: "line.diagonal")

  }
  .listStyle(SidebarListStyle())
}
    

Image of preview screen

3
  • 1
    SwiftUI does not support that - you have to create something like that manually. Commented Jul 3, 2022 at 10:40
  • Can I use UIKit to bridge with SwiftUI, and additionally with application going to get more bigger would it be right to use SwiftUI? Commented Jul 3, 2022 at 10:42
  • 1
    Using SwiftUI & UIKit inside the same app is totally fine. Have a look at UIViewRepresentable, UIViewControllerRepresentable & UIHostingController. Commented Jul 3, 2022 at 11:52

1 Answer 1

1

Here's a simple working example made with SwiftUI:

struct ContentView: View {
    var body: some View {
        NavigationView{
            
            TagView()
            
            Text("Default second View")
            Text("Default Third View")
        }
    }
}


struct TagView: View {
    let tags = ["Apple", "Google"]
    var body: some View {
        List{
            ForEach(tags, id: \.self) { name in
                NavigationLink {
                    ProductView(tag: name)
                } label: {
                    Text(name)
                }

            }
        }
    }
}


struct ProductView: View {
    var tag: String
    var products: [String] {
        if tag == "Apple" {
            return ["iPhone", "iPad", "MacBook"]
        } else {
            return ["resuable stuff"]
        }
    }
    var body: some View {
        List{
            ForEach(products, id: \.self) { name in
                NavigationLink {
                    DetailsView()
                } label: {
                    Text(name)
                }

            }
        }
    }
}


struct DetailsView: View {
    var body: some View {
        Text("Detailed explanation about product")
    }
}

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.