Home > Blockchain >  NavigationView ignores edgesIgnoreSafeArea(.top)
NavigationView ignores edgesIgnoreSafeArea(.top)

Time:03-15

I have troubles with navigation view. When I set its background color I see the child view below (red color backgroud). I want to take the top area as well for NavigationView.

struct ContentView: View {
    init() {
        UINavigationBar.appearance().backgroundColor = .black
    }

    var body: some View {
        NavigationView {
            ZStack {
                Color(.red).ignoresSafeArea()
                Text("Hello, world!")
                    .padding()
            }
            .navigationTitle("Main menu")
        }
        .edgesIgnoringSafeArea(.top)
    }
}

Simulator screenshoot

How to make it hover the space above?

CodePudding user response:

try this inside your view init():

 init() {
    let appearance = UINavigationBarAppearance()
    appearance.backgroundColor = .black
    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance 
    }
  • Related