Created
January 25, 2022 17:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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