[英]SwiftUI Custom Back Button Text for NavigationView
How can I change the back button text in a NavigationView
when a new View
is pushed?推送新View
时,如何更改NavigationView
中的后退按钮文本?
The default shows "Back" but I want to change it so something.默认显示“返回”,但我想更改它。
Is that currently possible in SwiftUI?目前在 SwiftUI 中是否可行?
Full Code:完整代码:
struct SampleDetails: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var btnBack: some View {
Button(action: {self.presentationMode.wrappedValue.dismiss()}) {
HStack {
Image("ic_back") // set image here
.aspectRatio(contentMode: .fit)
.foregroundColor(.white)
Text("Go back")
}
}
}
var body: some View {
List {
Text("sample code")
}
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading: btnBack)
}
}
For more clarification click here .如需更多说明,请单击此处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.