TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.