Created
September 13, 2022 11:14
-
-
Save iosdevronak/7501ef968dd078c6878e855c46d019a0 to your computer and use it in GitHub Desktop.
Working with Picker in SwiftUI
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 { | |
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