0

How can I remove separators from SwiftUI list in WatchOS?

I have gone through some answers in stackoverflow, they suggest to use

UITableView.appearance().tableFooterView = UIView()
UITableView.appearance().separatorStyle = .none

Looks like they only work for iOS and apparently they don't work for WatchOS SwiftUI list. Is there any way to customize it?

Edit -

UITableView.appearance().separatorStyle = .none

Apparently the above code doesn't hide the separators in iOS 14.

Mattia Righetti
  • 1,265
  • 1
  • 18
  • 31
Rizwan Ahmed
  • 919
  • 13
  • 19

2 Answers2

0

I'm not sure what do you mean by separator on WatchOS List, but probably you just need to set platter color as below for first row

enter image description here

var body: some View {
    List {
        Text("Hello, World!").listRowPlatterColor(Color.black)
        Text("Hello, World!")
        Text("Hello, World!")
    }
}
Asperi
  • 228,894
  • 20
  • 464
  • 690
  • It removes the background color. Still there is separator space between two cells. I need to remove them. What I have done is used edgesinset for the cell and have given a negative value for the top inset, but I am not sure if it is the right way. – Rizwan Ahmed Feb 04 '20 at 18:53
0

You can use listRowBackground() as Paul Hudson shows on Hacking with Swift

List {
    ForEach(0..<10) {
        Text("Row \($0)")
    }
    .listRowBackground(Color.red)
}

Edit to highlight the comment:

There's no API for modifying the List item spacing at present. You'd either have to create a custom ListStyle, or not use a List. If you use a ScrollView with a VStack you'll be able to get similar results. In this case you can set the spacing on the VStack to achieve the results you want.

Tristan Warner-Smith
  • 9,631
  • 6
  • 46
  • 75
  • But, what about the spacing between the cells. There seems to be a default space between the cells. I don’t want it though. – Rizwan Ahmed Feb 04 '20 at 18:59
  • 1
    There's no API for modifying this at present. You'd either have to create a custom ListStyle, or not use a List. If you use a ScrollView with a VStack you'll be able to get similar results. – Tristan Warner-Smith Feb 04 '20 at 19:10
  • For reference `WatchKit`'s equivalent for `UITableView` is `WKInterfaceTable` but as you've seen the Appearance proxy API `UIAppearance` doesn't exist on `WatchOS`. – Tristan Warner-Smith Feb 04 '20 at 19:17
  • Yes as @Tristan had specified, using ScrollView with a VStack is the only efficient way of achieving this. – Rizwan Ahmed Feb 10 '20 at 06:17