0

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

2 Answers2

1

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")
} 
Taimoor Arif
  • 750
  • 3
  • 19
  • how to give back action on <-- icon –  Oct 19 '22 at 08:38
  • 2
    @RazzaMishra Add an `@Environment(\.dismiss) var dismiss` to your view. Then make your icon with button, and call `dismiss()` in its action. That will pop the view off the stack in the same way the normal back button does. – ScottM Oct 19 '22 at 08:46
  • 1
    @RazzaMishra [check this](https://stackoverflow.com/questions/56513568/ios-swiftui-pop-or-dismiss-view-programmatically) – Taimoor Arif Oct 19 '22 at 08:55
0
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)
    
    }
    }