实际上,这是问题。我有一个这样的屏幕,我想更改BackButton。
我的视图屏幕:enter image description here
我想要代替带有标准图形数组和文本BACK的蓝色后退按钮,而只是没有文本的黑色数组。
换句话说,本质上是从后退按钮中删除文本,然后将颜色更改为黑色。怎么不实现呢?
您可以在希望为黑色且无文本的视图内使用适当的修饰符。您需要指定no button并提供您自己的图像以及返回功能。
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: SecondView()) {
Text("Hello, World!")
}
}
}
}
struct SecondView: View {
@Environment(\.presentationMode) var presentation
var body: some View {
VStack {
Text("Hello")
Text("Second view")
}
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading: Button(action: {
self.presentation.wrappedValue.dismiss()
}) {
Image(systemName: "chevron.left")
}
.foregroundColor(.black))
}
}
编辑:插入适当的图像。