Created
October 24, 2024 01:28
-
-
Save takoikatakotako/4e0545cce82a4f5d28ffc919798971a5 to your computer and use it in GitHub Desktop.
SwiftUIで複数行のPickerを作成する
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
| import SwiftUI | |
| struct ContentView: View { | |
| @State var selectedHour = 8 | |
| @State var selectedMinute = 30 | |
| var body: some View { | |
| GeometryReader { geometry in | |
| HStack { | |
| Picker(selection: $selectedHour, label: EmptyView()) { | |
| ForEach(0 ..< 24) { | |
| Text("\($0)") | |
| } | |
| } | |
| .pickerStyle(WheelPickerStyle()) | |
| .onReceive([selectedHour].publisher.first()) { (value) in | |
| print("hour: \(value)") | |
| }.labelsHidden() | |
| .frame(width: geometry.size.width / 2, height: geometry.size.height) | |
| .clipped() | |
| Picker(selection: $selectedMinute, label: EmptyView()) { | |
| ForEach(0 ..< 60) { | |
| Text("\($0)") | |
| } | |
| } | |
| .pickerStyle(WheelPickerStyle()) | |
| .onReceive([selectedMinute].publisher.first()) { value in | |
| print("minute: \(value)") | |
| } | |
| .labelsHidden() | |
| .frame(width: geometry.size.width / 2, height: geometry.size.height) | |
| .clipped() | |
| } | |
| } | |
| .padding() | |
| } | |
| } | |
| #Preview { | |
| ContentView() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment