Created
October 16, 2019 14:26
-
-
Save daveshah/084d3b9d5f65aabdda492d21209a55cf to your computer and use it in GitHub Desktop.
A quick way to implement WheelPickerStyle similarly to the DatePicker
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
@State private var options = ["option 1", "option 2", "option 3"] | |
@State private var selectedOption = 0 | |
@State private var showPicker = false | |
@State private var date = Date() | |
var body: some View { | |
Form { | |
Button(action: { self.showPicker.toggle() }){ | |
HStack { | |
Text("Options") | |
.foregroundColor(Color.black) | |
Spacer() | |
Text(options[selectedOption]) | |
.foregroundColor(self.showPicker ? Color.red : Color.gray) | |
} | |
} | |
if self.showPicker { | |
Picker("", selection: $selectedOption) { | |
ForEach(0 ..< options.count) { | |
Text(self.options[$0]).tag($0) | |
} | |
}.pickerStyle(WheelPickerStyle()) | |
} | |
DatePicker(selection: $date) { | |
Text("Date") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment