In a SwiftUI List on MacOS I want to have Dividers but no extra spacing between the lines.
The following example produces two Lists like this:
What I would like to have is:
Dividers in the second List with the "original" total height without extra spacing.
This is the code I tried:
struct TestViews_MacOS: View {
@State var selectedLine: String?
var body: some View {
VStack{
List(selection: $selectedLine) {
TestLineWithSeperator(text: "Line 1")
TestLineWithSeperator(text: "Line 2")
TestLineWithSeperator(text: "Line 3")
TestLineWithSeperator(text: "Line 4")
}
Text("==========================")
List(selection: $selectedLine) {
TestLineWithOutSeparator(text: "Line 1")
TestLineWithOutSeparator(text: "Line 2")
TestLineWithOutSeparator(text: "Line 3")
TestLineWithOutSeparator(text: "Line 4")
}
// .onReceive(NotificationCenter.default.publisher(for: NSView.frameDidChangeNotification)) {
// guard let tableView = $0.object as? NSTableView else { return }
// print("set inte to 0")
// tableView.intercellSpacing = .zero
// }
//.listStyle(DefaultListStyle())
//.listStyle(InsetListStyle())
//.listStyle(PlainListStyle())
//.listStyle(SidebarListStyle())
//.listRowInsets(.none)
Spacer()
HStack{
Text("\(selectedLine ?? "nothing Selected")").padding()
Spacer()
}
}
}
}
struct TestLineWithSeperator: View {
var text: String
var body: some View {
VStack {
HStack{
Text(text)
// .padding(.top, -4)
// .padding(.bottom, -4)
// .listRowInsets(.none)
// .border(Color.green)
Spacer()
}.padding(0)
Divider()
}
.padding(0)
.tag("x \(text)")
}
}




