如何在 SwiftUI 中使用 PageTabViewStyle 摆脱 TabView 上的索引点?

How can I get rid of index dots on TabView with PageTabViewStyle in SwiftUI?

我有以下代码,但似乎无法删除 TabView 底部的点。

struct ContentView: View {
    @Environment(\.managedObjectContext) private var viewContext
    
    @State var users = ["Janice", "Emily", "Candice", "London", "Julia"]

    var body: some View {
        TabView {
            ForEach(users, id: \.self) { user  in
                UserCard(user: user)
            }
        }
        .tabViewStyle(PageTabViewStyle())
        .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .never))
        .background(Color(.systemGroupedBackground))
    }
}

struct UserCard: View {
    
    let user: String
    
    var body: some View {
        Color.white
            .padding(30)
    }
}

我原以为 PageIndexViewStyle(backgroundDisplayMode: .never) 会删除索引点,但这是行不通的。有没有其他方法可以摆脱它们?

试试这个:

struct ContentView: View {
    @Environment(\.managedObjectContext) private var viewContext
    @State var users = ["Janice", "Emily", "Candice", "London", "Julia"]

    var body: some View {
        TabView {
            ForEach(users, id: \.self) { user  in
                UserCard(user: user)
            }
        }
        .tabViewStyle(.page(indexDisplayMode: .never))  // <--- here
        .background(Color(.systemGroupedBackground))
    }
}

struct UserCard: View {
    let user: String
    var body: some View {
        Text(user)
    }
}