从 SwiftUI 中的列表中删除滚动条占位符
Remove scroll bar placeholders from List in SwiftUI
我正在尝试使用 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()
}
}
谁能帮我从列表中删除这个滚动条?
macOS:10.15.6
Xcode: 12.0
Swift: 5.3
我假设您刚刚在系统偏好设置中激活了显示滚动条到Always
。这是 system-wide 功能。只是 select 其他选项。
我正在尝试使用 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()
}
}
谁能帮我从列表中删除这个滚动条?
macOS:10.15.6 Xcode: 12.0 Swift: 5.3
我假设您刚刚在系统偏好设置中激活了显示滚动条到Always
。这是 system-wide 功能。只是 select 其他选项。