Home > OS >  how to hide back button icon and text both from navigation View in swiftui?
how to hide back button icon and text both from navigation View in swiftui?

Time:10-19

ScreenShot of Navigation bar

want to replace from < back to right arrow(<--) All in swiftui.

And when we will click on the <-- icon and then return to the source View

CodePudding user response:

struct SourceView: View {    
     @Environment(\.dismiss) var dismiss   
    var body: some View {
       
         NavigationView {
    
    

 NavigationLink(destination: DestinationView().navigationTitle("")
                                         .navigationBarHidden(true)
                                         .navigationBarBackButtonHidden(true)){
                                         AsyncImage(url: URL(string: item.url)){image in
                                             image
                                                 .resizable().frame(width: UIScreen.main.bounds.width/2.2, height:
 45).cornerRadius(10)
                                             
                                         }placeholder: {
                                             Image("logo_gray").resizable().frame(width:  UIScreen.main.bounds.width/2.2, height: 45).cornerRadius(10)
                                         }
                                     }
 

This is destination View

struct DestinationView: View {
        @Environment(\.dismiss) var dismiss      // For Dismiss the view
        
        var body: some View {
           
                VStack {
                    
                    HStack(spacing: 25){
                        Button(action: {
                            dismiss()
                        }, label: {
                            Image(systemName: "arrow.left").font(.system(size: 25))
                        })
                            
                     
                        Text("All").font(.system(size: 25))
                        Spacer()
                    }.padding(.horizontal).frame(height: 75).background(Color("orange")).foregroundColor(.white)
    
    }
    }

CodePudding user response:

Use these lines in the end of the View:

.navigationTitle("")
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)

Like this:

struct ContentView: View {
   var body: some View {
   
     VStack {
         }
     .navigationTitle("")
     .navigationBarHidden(true)
     .navigationBarBackButtonHidden(true)
   }
}

Or you can use this where you add your Navigation Link on the previous View as:

NavigationLink {
           ContentView() // your view
               .navigationTitle("")
               .navigationBarHidden(true)
               .navigationBarBackButtonHidden(true)

    } label: {
        Text("move to next screen")
} 
  • Related