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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.