Skip to content

Instantly share code, notes, and snippets.

@herzi
Created June 11, 2019 16:44
Show Gist options
  • Save herzi/e5ad7f6e00dd296c151129ddb51355d3 to your computer and use it in GitHub Desktop.
Save herzi/e5ad7f6e00dd296c151129ddb51355d3 to your computer and use it in GitHub Desktop.
//
// Picker+Style.swift
//
// Copyright 2019, Sven Herzberg
//
// License: MIT
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
import SwiftUI
enum Pickable: CaseIterable {
case axe
case tooth
}
struct WheelPickerView: View {
@State var picked: Pickable
var body: some View {
Picker(selection: $picked, label: Text("Pick!")) {
ForEach(Pickable.allCases.identified(by: \.self)) { pickable in
Text(String(describing: pickable))
.tag(pickable)
}
}
.pickerStyle(.wheel)
.frame(minWidth: 300,
maxWidth: .infinity,
alignment: .center)
}
}
#if DEBUG
struct WheelPickerView_Previews: PreviewProvider {
static var previews: some View {
Group {
WheelPickerView(picked: .axe)
.previewDisplayName("Without List")
NavigationView {
List {
WheelPickerView(picked: .axe)
.navigationBarTitle(Text("Wheel Picker"))
}
}.previewDisplayName("With List")
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment