PageTabViewStyle Right to left

Viewed 213

I have a TabView with PageTabViewStyle as the tabViewStyle on it inside the TabView are multiple views and it works perfectly fine but I want it to start from the right then continue to the left like the first view starts from the right then swipe to the left to see the second view.

Your help is much appreciated.

1 Answers

you can use this way for that.

  1. Put a tag in subview of the PageTabView
  2. put the tag of the last view in selectedTab



struct ContentView: View {
    
    // put the tag number of the last page
    @State private var selectedTab = 2
    
    var body: some View {
        VStack {
            TabView(selection: $selectedTab){
                Text("First Page")
                    .tag(0)
                Text("Second Page")
                    .tag(1)
                Text("Third Page")
                    .tag(2)
            }
            .frame(width: 300, height: 500)
            .tabViewStyle(PageTabViewStyle())
            .background(Color.purple)
            .cornerRadius(15)
        }
    }
}



enter image description here

Related