How can I add text in between the NavigationLink title and the arrow/disclosure indicator as shown in the left image below?
SwiftUI Code:
struct NavigationStackTest: View {
let fruits = ["Orange", "Apple"]
var body: some View {
NavigationStack{
VStack{
List(fruits, id:\.self){ fruit in
HStack{
//Text("Details")
NavigationLink(fruit, value: fruit)
Text("Details")
}
}
.navigationDestination(for: String.self) { item in
Text(verbatim: item)
}
}
}
}
}
>Solution :
Right now, you’re just passing a String label to the NavigationLink. Instead, you can pass a View and use an HStack and Spacer to lay out your content:
List(fruits, id:\.self){ fruit in
NavigationLink(value: fruit) {
HStack {
Text(fruit)
Spacer()
Text("Details")
}
}
}
