Last active
November 30, 2023 16:45
-
-
Save devs-rootstrap/0e59cb72b60ad811fdf2dd8ebd271d08 to your computer and use it in GitHub Desktop.
SwiftUI Picker Example
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
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() | |
} | |
} | |
} |
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
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) | |
} | |
} | |
} | |
} |
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
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") | |
} | |
} | |
} | |
} | |
} |
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
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