Search code examples
swiftuipaddingnavigationview

SwiftUI adding a button to navigationView applies padding to whole view


I have a view which looks like this:

enter image description here

And here is its the code:

    struct SettingController: View {
    var body: some View {
        NavigationView() {
            MainList()
                .navigationBarTitle("Settings")
        }
    }
}

Now I add a code to add a button to navigationView like so:

    struct SettingController: View {
    @State var isToggle: Bool = false
    var body: some View {
        NavigationView() {
            MainList()
                .navigationBarTitle("Settings")
                .navigationBarItems(trailing:
                                        HStack {
                                            Button("Unlock All") {
                                                isToggle.toggle()
                                            }.sheet(isPresented: self.$isToggle) {
                                                SubscriptionModalView()
                                            }
                                        })
        }
    }
}

But the results came out like this:

enter image description here

How do I get rid of those paddings!?


Solution

  • List(..) {
       ListItem {
       ..
       }
       .listStyle(PlainListStyle())
    }
    

    Try using PlainListStyle