Skip to content

Instantly share code, notes, and snippets.

@iosdevronak
Created September 13, 2022 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iosdevronak/7501ef968dd078c6878e855c46d019a0 to your computer and use it in GitHub Desktop.
Save iosdevronak/7501ef968dd078c6878e855c46d019a0 to your computer and use it in GitHub Desktop.
Working with Picker in SwiftUI
import SwiftUI
struct ContentView: View {
let fruitList = ["Apple", "Mango", "Banana", "Grapes"]
@State var myFruit : String = "Apple"
var body: some View {
VStack {
Picker("Select color", selection: $myFruit) {
ForEach(fruitList, id: \.self) {
Text($0)
}
}
.pickerStyle(.segmented)//Sets the style for pickers
}
}
}
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