Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add text in between the NavigationLink title and the arrow / disclosure indicator – SwiftUI

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)
                }
            }
        }
    }
}

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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")
        }
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading