Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 694

Apply custom border to each row in a List with SwiftUI

$
0
0

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)        }    }}

enter image description here


Viewing all articles
Browse latest Browse all 694

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>