我想在 SwiftUI 中隐藏导航栏只显示后退按钮
I want to hide the navigation bar and display only the back button in SwiftUI
navigationBarTitle 已隐藏。
如何在此状态下显示后退按钮?
struct SampleView: View {
var body: some View {
ScrollView() {
Text("text")
}
.navigationBarTitle("")
.navigationBarHidden(true)
}
}
当您执行以下操作时,顶部会出现空白。
此外,如果您滚动,将显示一个条。
struct SampleView: View {
var body: some View {
ScrollView() {
Text("text")
}
.navigationBarTitle("")
}
}
这里是添加自定义按钮而不是导航栏的方法
struct DestinationView: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var body: some View {
VStack(alignment: .center, spacing: 0){
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}) {
Image(systemName: "backward.fill").padding()
Spacer()
}
Spacer()
}
.navigationBarTitle("")
.navigationBarHidden(true)
}
}
navigationBarTitle 已隐藏。 如何在此状态下显示后退按钮?
struct SampleView: View {
var body: some View {
ScrollView() {
Text("text")
}
.navigationBarTitle("")
.navigationBarHidden(true)
}
}
当您执行以下操作时,顶部会出现空白。 此外,如果您滚动,将显示一个条。
struct SampleView: View {
var body: some View {
ScrollView() {
Text("text")
}
.navigationBarTitle("")
}
}
这里是添加自定义按钮而不是导航栏的方法
struct DestinationView: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var body: some View {
VStack(alignment: .center, spacing: 0){
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}) {
Image(systemName: "backward.fill").padding()
Spacer()
}
Spacer()
}
.navigationBarTitle("")
.navigationBarHidden(true)
}
}