Skip to content

Instantly share code, notes, and snippets.

@devs-rootstrap
Last active November 30, 2023 16:45
Show Gist options
  • Save devs-rootstrap/0e59cb72b60ad811fdf2dd8ebd271d08 to your computer and use it in GitHub Desktop.
Save devs-rootstrap/0e59cb72b60ad811fdf2dd8ebd271d08 to your computer and use it in GitHub Desktop.
SwiftUI Picker Example
import SwiftUI
struct ContentView: View {
@State private var favoriteFruit = 1
var body: some View {
VStack(spacing: 20) {
Text("SwiftUI Picker")
.font(.largeTitle)
Text("Customized Style")
.font(.title2)
Text("Filled")
.font(.title3)
// Filled Picker Example
Picker("Fruits", selection: $favoriteFruit){
Text("Banana").tag(0)
Text("Apple").tag(1)
Text("Strawberry").tag(2)
}
.pickerStyle(.wheel)
.background(RoundedRectangle(cornerRadius:15)
.fill(.orange))
.padding()
Text("Bordered")
.font(.title3)
// Bordereed Picker Example
Picker("Fruits", selection: $favoriteFruit){
Text("Banana").tag(0)
Text("Apple").tag(1)
Text("Strawberry").tag(2)
}
.pickerStyle(.wheel)
.background(RoundedRectangle(cornerRadius:15)
.stroke(.orange))
.padding()
}
}
}
import SwiftUI
struct ContentView: View {
@State private var favoriteFruit = 1
var body: some View {
VStack(spacing: 20) {
Text("SwiftUI Picker")
.font(.largeTitle)
Text("Introduction")
.font(.title2)
Picker("Fruits", selection: $favoriteFruit){
Text("Banana").tag(0)
Text("Apple").tag(1)
Text("Orange").tag(2)
}
}
}
}
import SwiftUI
struct ContentView: View {
@State private var favoriteFruit = 1
var body: some View {
NavigationStack {
VStack(spacing: 20) {
Text("SwiftUI Picker")
.font(.largeTitle)
Text("NavigationLink")
.font(.title2)
Picker("Fruits", selection: $favoriteFruit){
Text("Banana").tag(0)
Text("Apple").tag(1)
Text("Strawberry").tag(2)
}
.padding()
.pickerStyle(.navigationLink)
}
}
}
}
struct ContentView: View {
@State private var favoriteFruit = 1
var body: some View {
VStack(spacing: 20) {
Text("SwiftUI Picker")
.font(.largeTitle)
Text("Section")
.font(.title2)
Picker("Fruits", selection: $favoriteFruit){
Section {
Text("Banana").tag(0)
} header: {
Text("Yellow")
}
Section {
Text("Apple").tag(1)
Text("Strawberry").tag(2)
} header: {
Text("Red")
}
}
}
}
}
import SwiftUI
struct ContentView: View {
@State private var favoriteFruit = 1
var body: some View {
VStack(spacing: 20) {
Text("SwiftUI Picker")
.font(.largeTitle)
Text("Style")
.font(.title2)
// Picker Automatic
Text("Automatic")
.font(.headline)
Picker("Fruits", selection: $favoriteFruit){
Text("Banana").tag(0)
Text("Apple").tag(1)
Text("Strawberry").tag(2)
}.pickerStyle(.automatic)
// Picker Segmented
Text("Segmented")
.font(.headline)
Picker("Fruits", selection: $favoriteFruit){
Text("Banana").tag(0)
Text("Apple").tag(1)
Text("Strawberry").tag(2)
}.pickerStyle(.segmented)
// Picker Wheel
Text("Wheel")
.font(.headline)
Picker("Fruits", selection: $favoriteFruit){
Text("Banana").tag(0)
Text("Apple").tag(1)
Text("Strawberry").tag(2)
}.pickerStyle(.wheel)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment