Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI List Rows fill width

In SwiftUI 2.0, i have a List with some text (MacOS App)

typealias Row = String

@State var row: [Row] = ["1 Row with some content", "2 Some content", "3 Another Row"]

List(row, id: \.self) { content in
    Text(content)
        .truncationMode(.middle)
        .lineLimit(1)
        .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
        .background(Color.blue)
}

This leads to the following output in preview:

enter image description here

How can i make the rows fill all available space? (Blue Frame of List should match blue background of text)

Adding a .listStyle(PlainListStyle()) to the List element, reduces the space, but not enough:

enter image description here

like image 539
flymg Avatar asked Oct 15 '25 19:10

flymg


1 Answers

You can try with this:

    Text(content)
        .listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
        .clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
        .listRowBackground(Color.white.opacity(0))
like image 107
Bill Haku Avatar answered Oct 17 '25 08:10

Bill Haku



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!