1
votes

I would like to know how to remove the extra space between SwiftUI List and NavigationBar. Kindly see photo below for reference.

Note that I tried adding top padding -> .padding (.top,-100) in NewsHomeView but its not a good solution because on bigger screen resolution, I can still see that extra space between the NavigationBar and the ListView.

Here’s the code of my NewsHomeView and ContainerView. Note that I need to use ZStack for NewHomeView and Slider for me to achieve a certain goal.

struct ContainerView: View {

    @State private var show = false
    var body: some View {
            NavigationView {
                ZStack {
                    NewsHome()
                    Slider(showMenu: $show)
                }
                .navigationBarTitle("News", displayMode: .inline)
            }
    }
}

struct NewsHomeView: View {
    @ObservedObject private var newsListViewModel = NewsListViewModel()
    init() {
        newsListViewModel.load()
    }
    var body: some View {
         NewsListView(newsCollection: self.newsListViewModel.newsCollection, imageData: self.newsListViewModel.imageData)
        .listStyle(GroupedListStyle())

    }
}

enter image description here

1

1 Answers

1
votes

It is not provided what's inside NewsListView, but it is due to List style, so

 NewsListView(newsCollection: self.newsListViewModel.newsCollection, imageData: self.newsListViewModel.imageData)
   // .listStyle(GroupedListStyle()) << comment this or use PlainListStyle