Quantcast
Viewing latest article 18
Browse Latest Browse All 602

Apply custom border to each row in a List with SwiftUI

So, I want a List in SwiftUI, where the border of each row depends on some function of the contents of the row. Normally I can do this easily with .border() but List seems to take care of the styling for the elements itself, adding padding and that.

The closest I have is below, which is quite far from what I'm after. This produces the borders around the text fields, but I want instead to produce borders around the whole cell.

struct ListDemoView: View {    @State private var nums: [Int] = [1, 2, 3, 4, 5]    var body: some View {        List (nums, id: \.self) { num in            Section {                Text("Num: \(num)")            }            .border(num % 2 == 0 ? Color.red : Color.blue)        }    }}

Image may be NSFW.
Clik here to view.
enter image description here


Viewing latest article 18
Browse Latest Browse All 602

Trending Articles