1

I am using xcode 13.2.1 iOS 15,i want to hide the navigational bar and the back arrow i have tried several methods. none of the answers worked

var body: some View {
    NavigationView{
        ZStack{
                Text("Header") //Header View
                Spacer ()
                Text("Main")//Main View
                Spacer()
                Spacer()
                Text("Bottom") //Bottom View
        }.navigationTitle("")
        .navigationBarHidden(true)
        
    }.navigationViewStyle(.stack)
}
abinbabu
  • 43
  • 8

2 Answers2

1

A better SwiftUI approach is to create a @State property to toggle the state.

@State private var hideNavigationbar: Bool = false

You switching the value in .onAppear {} to true. When you dismiss the view you call .onDisappear {} and set the property to false.

Now you can use it like so:

.navigationbarHidden(hideNavigationbar)
adri567
  • 533
  • 5
  • 20
-1

I fixed this on xcode 12.5 by adding this:

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        UIApplication.shared.isStatusBarHidden = true // <== ADD THIS LINE
        return true
    }
}

and then under info.plist I added

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

using xml type.

Also I had .navigationBarHidden(true) on the upmost level in the view, so for you, the NavigationView.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Ari Steinfeld
  • 366
  • 1
  • 6