Created
June 19, 2020 04:17
-
-
Save laevandus/3eeaca92b8d80a8fc070d7ce41aae12b to your computer and use it in GitHub Desktop.
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
import SwiftUI | |
struct ContentView: View { | |
@State private var selectedFruit: Fruit = .orange | |
var body: some View { | |
NavigationView { | |
Form { | |
Section { | |
makeFruitPicker() | |
makePlanetPicker() | |
}.navigationBarTitle("Pickers") | |
} | |
}.navigationViewStyle(StackNavigationViewStyle()) | |
} | |
// MARK: Picker with Segmented Style | |
enum Fruit: String, CaseIterable { | |
case apple, orange, pear | |
} | |
func makeFruitPicker() -> some View { | |
Picker("Fruits", selection: $selectedFruit) { | |
ForEach(Fruit.allCases, id: \.rawValue) { fruit in | |
Text(fruit.rawValue).tag(fruit) | |
} | |
}.pickerStyle(SegmentedPickerStyle()) | |
} | |
// MARK: Picker with Default Style | |
@State private var selectedPlanet = "" | |
let planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Neptune", "Uranus"] | |
func makePlanetPicker() -> some View { | |
Picker("Planets", selection: $selectedPlanet) { | |
ForEach(planets, id: \.self) { planet in | |
Text(planet) | |
}.navigationBarTitle("Planets") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment