Search code examples
swiftuiswiftui-list

SwiftUI List alignment


Why is the default alignment of a SwiftUI List so wacky? How do I get the text to left align?

enter image description here

My current code:

        NavigationStack {
            List {
                ForEach(users) { user in
                    VStack {
                        Text(user.name)
                            .font(.headline)
                        Text(user.description)
                    }
            }
        }
            .navigationTitle("Profiles")
        }

Solution

  • It's because of the VStack alignment, not the List. The default value is .center:

    @inlinable public init(alignment: HorizontalAlignment = .center, spacing: CGFloat? = nil, @ViewBuilder content: () -> Content)

    VStack(alignment: .leading) {
        ...
    }