4

我有以下代码,但似乎无法删除 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) 会删除索引点,但这不起作用。有没有其他方法可以摆脱它们?

4

1 回答 1

6

试试这个:

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)
    }
}
于 2021-07-09T02:40:03.333 回答