szakes1
szakes1

Reputation: 904

How to remove padding on top of NavigationView?

I'm wondering how to remove the top padding just above the NavigationView in SwiftUI.

Here's the problem: Xcode 1

Code:

import SwiftUI

struct HomeView: View {
    
    var deeds: [Deed] = deedsData
    
    var body: some View {
        NavigationView {
            List(deeds) { item in
                Image(systemName: "doc.fill")
                
            }
            .navigationTitle(Text("title"))
        }
    }
}

struct HomeView_Previews: PreviewProvider {
    static var previews: some View {
        HomeView(deeds: deedsData)
    }
}

Upvotes: 5

Views: 5327

Answers (3)

TomerBu
TomerBu

Reputation: 1503

The space is intended. it makes room for the toolbar items.

however, you could go for negative padding like so:

struct ContentView: View {
    var body: some View {
        NavigationView{
            YourListView()
                .navigationTitle("Title")
        }.padding(.top, -50)
    }
}

Upvotes: 1

Asperi
Asperi

Reputation: 257711

Remove NavigationView from HomeView, there seems one already present in parent view (and it is enough to construct navigation stack)

struct HomeView: View {
    
    var deeds: [Deed] = deedsData
    
    var body: some View {
        List(deeds) { item in
            Image(systemName: "doc.fill")
            
        }
        .navigationTitle(Text("title"))
    }
}

Upvotes: 1

pawello2222
pawello2222

Reputation: 54486

This is the appearance of the large navigation bar.

You can use the inline style instead:

List(deeds) { item in
    Image(systemName: "doc.fill")
    
}
.navigationTitle(Text("title"))
.navigationBarTitleDisplayMode(.inline) // change style

Upvotes: 5

Related Questions