1

I am working with NavigationView in SwiftUI and having an issue with it extending fully to the bottom of the screen.

I created a simple List in and this works fine. However, when I put it in a NavigationView, it creates a gray area at the bottom. I've tried adjusting the frame and a number of other things to no avail. I've never seen this before. Any help would be appreciated.

Simple List View

Added To NavigationView

struct ListingView: View {
    var body: some View {
        List(0..<5) { item in
            Text("Test")
        }
    }
}

struct ListingView: View {
    var body: some View {
        NavigationView {
            List(0..<5) { item in
                Text("Test")
            }
        }
    }
}

struct ContentView: View {
    // PacificBlue Background Set Up.
    init() {
        UITabBar.appearance().isTranslucent = false
        UITabBar.appearance().barTintColor = UIColor(Color.pacificBlue)
    }
    
    // MARK: View
    var body: some View {
        TabView {
            SeafoodListView()
                .tabItem {
                    Image(systemName: "line.diagonal.arrow")
                    Text("Market")
                }.tag(0) // SeafoodMarketView
            ListingView()
                .tabItem {
                    Image(systemName: "list.bullet.rectangle")
                    Text("Listings")
                }.tag(1) // ListingView
            RequestView()
                .tabItem {
                    Image(systemName: "megaphone")
                    Text("Requests")
                }.tag(2) // RequestView
            MessengerView()
                .tabItem {
                    Image(systemName: "ellipsis.bubble")
                    Text("Messenger")
                }.tag(3) // MessengerView
            AccountView()
                .tabItem {
                    Image(systemName: "person")
                    Text("Account")
                }.tag(4) // AccountView
        } // TabView
        .accentColor(.white)
    }
}

// MARK: Preview
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
outis
  • 75,655
  • 22
  • 151
  • 221
jonthornham
  • 2,881
  • 4
  • 19
  • 35

1 Answers1

3

This is due to hack with appearance...

init() {
//    UITabBar.appearance().isTranslucent = false   // remove this line !!!
    UITabBar.appearance().barTintColor = UIColor(Color.pacificBlue)
}

Alternate: replace entire appearance with configured opaque background

init() {

    let newAppearance = UITabBarAppearance()
    newAppearance.configureWithOpaqueBackground()
    newAppearance.backgroundColor = UIColor(Color.pacificBlue)
    UITabBar.appearance().standardAppearance = newAppearance

}
Asperi
  • 228,894
  • 20
  • 464
  • 690