【问题标题】:How to replace <Back button with < in SwiftUI NavigationBarItem?如何在 SwiftUI NavigationBarItem 中用 < 替换 <Back 按钮?
【发布时间】:2021-04-25 04:00:27
【问题描述】:

我想用&lt;替换&lt; Back我当前的尝试只是添加一个新的NavigationItem。


struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink(
                destination: ContentView2(),
                label: {
                    Button(action: {}, label: {
                        Text("Button")
                    }).disabled(true)
                })
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct ContentView2: View {
    var body: some View {
        Text("wdfokjokjokjokjwdofjk")
            .padding()
            .navigationBarItems(leading: Image(systemName: "chevron.left").foregroundColor(.green))
    }
}

【问题讨论】:

标签: swift swiftui


【解决方案1】:

Backprevious 屏幕的默认词,当那里没有提供标题时。最简单的就是使用空标题,比如

NavigationLink(
    destination: ContentView2(),
    label: {
        Button(action: {}, label: {
            Text("Button")
        }).disabled(true)
    })
    .navigationTitle("")      // << here - empty title !!

给予

【讨论】:

    猜你喜欢
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    相关资源
    最近更新 更多