UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How to set the width of a Navigation and SideBar

Forums > SwiftUI

Dear .all

I have a content view with a.... okay let the code spreak for it selfs.

`

 struct ContentView: View {
    // .....
    var body: some View {
        HStack{
            NavigationView {

                SideBarView_HWS().frame(minWidth: 200,idealWidth: 250,maxWidth: 260, maxHeight: .infinity )

                BodyInfoStartView()

            } //  .frame(minWidth: 200,idealWidth: 250,maxWidth: 260, maxHeight: .infinity ) <<< this isn't working
        }
    }
 }

 struct SideBarView_HWS: View {
    //....
    @State private var clientExpanded: Bool = true
    @State var selection: String?

    var body: some View {
        VStack  {
            List(selection: $selection) {
                ForEach(agendaItems, id: \.self) { string in
                        NavigationLink(destination: AgendaFrameView(description: string)) {
                            Text(string)
                        }
                    }
                NavBarSection2()
            }
            .listStyle(SidebarListStyle())

            Divider()

            DisclosureGroup("Show some Text", isExpanded: $clientExpanded) {
                Text("Some Text...")
                    .padding()
                Text("Hello, Mars!").padding()
            }
            .padding()

            Divider()

            Text( "<Moonwalker is talking>")
        }
    }
 }

`

My goal is; I need to have both, the sideBar and the NavigationView, having the same maxWidth constraints. If I add a .frame to the navigationView the NavigationView and SideBar dissapears. If I us the .frame with Width constraints only to the SideBar then only the sideBar get shrinked but the NavigationView stays to its too width size.

How can I solve this? Its for iPadOS ( not iPhone )

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.