UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: SwiftUI List with key value pairs

Forums > SwiftUI

How can I make a list row in SwiftUI like this

With this light grey description on the right side. I know that it is possible but i forgot how to make it. I think it‘s sth with Spacer()

2      

You could try this

struct ListRows: View {
    let title: String
    let type: String

    var body: some View {
        HStack {
            Text(title)
                .font(.headline)

            Spacer()

            Text(type)
                .font(.headline)
                .foregroundColor(.secondary)
        }
    }
}

Then could put that into your List

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                ListRows(title: "Name", type: "Nigel's iPhone  12")
                ListRows(title: "Software Version", type: "15.3.1")
                ListRows(title: "Model Name", type: "iPhone 12 Pro Max")
            }
            .listStyle(.grouped)
            .navigationTitle("About")
            .navigationBarTitleDisplayMode(.inline)
        }
    }
}

3      

Yeah that works thanks :)

2      

Hello @NigelGee, it is me again, a few months later. I just realized that wahat I was looking for was .badge("String") Surprisinlgy this works.

The newest version of SwiftUI also introduced a new element, which also does this:

LabeledContent("Left") {
    Text("Right")
}

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.