swiftmacosswiftuisidebarliststyle

Remove scroll bar placeholders from List in SwiftUI


I am trying to create SibeBarList in SwiftUI using List, My code:

import SwiftUI

struct DetailView: View {
    let text: String
    
    var body: some View {
        Text(text)
            .frame(maxWidth: .infinity, maxHeight: .infinity)
    }
}


struct ContentView: View {
    private let names = ["Homer", "Marge", "Bart", "Lisa"]
    @State private var selection: String?
    var body: some View {
        NavigationView {
            List(selection: $selection) {
                Section(header: Text("The Simpsons")) {
                    ForEach(names, id: \.self) { name in
                        NavigationLink(destination: DetailView(text: name)) {
                            Text(name)
                        }
                    }
                }
            }.listStyle(SidebarListStyle())
            DetailView(text: "Make a selection")
        }
    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Result

Can someone help me remove this scrollbars from the list?

macOS: 10.15.6 Xcode: 12.0 Swift: 5.3


Solution

  • I assume you just activated Show scroll bars to Always in System Preferences. It is system-wide feature. Just select other option.

    demo