Created
September 21, 2021 20:48
-
-
Save joeblau/0c6ed144c685f98a79ea1477697e5aee to your computer and use it in GitHub Desktop.
Segment Control + Pages
This file contains hidden or 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
// | |
// ContentView.swift | |
// SegPage | |
// | |
// Created by Joe Blau on 9/21/21. | |
// | |
import SwiftUI | |
enum Page: Identifiable, CaseIterable, CustomStringConvertible { | |
public var id: Self { self } | |
case first, second, third | |
var description: String { | |
switch self { | |
case .first: return "First" | |
case .second: return "Second" | |
case .third: return "Third" | |
} | |
} | |
} | |
struct ContentView: View { | |
@State var pages: Page = .first | |
var body: some View { | |
VStack { | |
Picker("Current Page", selection: self.$pages) { | |
ForEach(Page.allCases) { page in | |
Text(page.description) | |
} | |
} | |
.pickerStyle(.segmented) | |
TabView(selection: self.$pages) { | |
FirstPageView() | |
.tag(Page.first) | |
SecondPageView() | |
.tag(Page.second) | |
ThirdPageView() | |
.tag(Page.third) | |
} | |
.tabViewStyle(PageTabViewStyle()) | |
.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always)) | |
.animation(.easeInOut) | |
.transition(.slide) | |
} | |
} | |
} | |
struct FirstPageView: View { | |
var body: some View { | |
Text("First Page") | |
} | |
} | |
struct SecondPageView: View { | |
var body: some View { | |
Text("Second Page") | |
} | |
} | |
struct ThirdPageView: View { | |
var body: some View { | |
Text("Third Page") | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment