如何在swiftui中隐藏后退按钮图标和文本?

9jyewag0  于 2022-10-31  发布在  Swift
关注(0)|答案(2)|浏览(187)

ScreenShot of Navigation bar
我想替换swiftui中从**〈后退右箭头(〈--)的所有**。
而当我们将点击**〈--**图标然后返回到源View

5us2dqdw

5us2dqdw1#

在视图末尾使用这些

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

就像这样:

struct ContentView: View {
   var body: some View {

     VStack {
         }
     .navigationTitle("")
     .navigationBarHidden(true)
     .navigationBarBackButtonHidden(true)
   }
}

或者,您也可以使用此选项,将您的导航链接添加到上一个视图中,作为:

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

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

c86crjj02#

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)
                                         }
                                     }

这是目标视图

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)

    }
    }

相关问题