Skip to content

Instantly share code, notes, and snippets.

@ramzesenok
Created January 25, 2022 17:34
Show Gist options
  • Save ramzesenok/9ad24728ad26b26907073d14a5405e03 to your computer and use it in GitHub Desktop.
Save ramzesenok/9ad24728ad26b26907073d14a5405e03 to your computer and use it in GitHub Desktop.
An example of a view with a segmented picker and a paginated tab view that are bound to each other
enum Page: Identifiable, CaseIterable {
case first, second
var title: String {
switch self {
case .first:
return "First"
case .second:
return "Second"
}
}
var id: Int {
hashValue
}
}
struct ContentView: View {
@State private var selectedPage = Page.first
var body: some View {
VStack {
Picker("Page picker", selection: $selectedPage.animation()) {
ForEach(Page.allCases) { page in
Text(page.title)
.tag(page)
}
}
.pickerStyle(SegmentedPickerStyle())
TabView(selection: $selectedPage) {
ForEach(Page.allCases) { page in
ZStack {
switch page {
case .first:
Text("First screen")
case .second:
Text("Second screen")
}
}
.tag(page)
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
}
.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment