Skip to content

Instantly share code, notes, and snippets.

@daveshah
Created October 16, 2019 14:26
Show Gist options
  • Save daveshah/084d3b9d5f65aabdda492d21209a55cf to your computer and use it in GitHub Desktop.
Save daveshah/084d3b9d5f65aabdda492d21209a55cf to your computer and use it in GitHub Desktop.
A quick way to implement WheelPickerStyle similarly to the DatePicker
@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