从SwiftUI的列表中删除滚动条占位符

时间:2020-09-19 18:16:29

标签: swift macos swiftui sidebarliststyle

我正在尝试使用List在SwiftUI中创建SibeBarList, 我的代码:

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

有人可以帮我从列表中删除此滚动条吗?

macOS:10.15.6 Xcode:12.0 斯威夫特:5.3

1 个答案:

答案 0 :(得分:1)

我假设您刚刚在系统偏好设置中将显示滚动条激活到Always。它是系统范围的功能。只需选择其他选项即可。

demo