Home > AI > IOS > SwiftUI >

PageTabViewStyle with customized indicator

struct ContentView: View {
    
    @State private var selectedPage = 0
    
    var body: some View {
        
        VStack {
            HStack {
                Button {
                    if selectedPage > 0 {
                           withAnimation { selectedPage -= 1 }
                       }
                } label: {
                    Image(systemName: "chevron.left.circle")
                }
                
                Spacer().frame(width: 40)

                Button {
                    if selectedPage < 2 {
                           withAnimation { selectedPage += 1 }
                       }
                } label: {
                    Image(systemName: "chevron.right.circle")
                }
            }
            
            TabView(selection: $selectedPage) {
                Text("Hi").tag(0)
                Text("Hello").tag(1)
                Text("Welcome").tag(2)
            }
            .tabViewStyle(PageTabViewStyle())
       }
        .padding()
    }
}

Leave a Reply