Picker with hours and minutes

Hi, I'm trying to accomplish this picker:


Right now I have this:


HStack {
                            Spacer()
                            
                            Picker("", selection: $hours){
                                ForEach(0..<4, id: \.self) { i in
                                    Text("\(i) hours").tag(i)
                                }
                            }
                            .pickerStyle(WheelPickerStyle())
                            .frame(width: 180)
                            .clipped()
                            
                            
                            Picker("", selection: $minutes){
                                ForEach(0..<60, id: \.self) { i in
                                    Text("\(i) min").tag(i)
                                }
                            }
                            .pickerStyle(WheelPickerStyle())
                            .frame(width: 180)
                            .clipped()
                            
                            Spacer()
                        }



and even though that works, the design is very bad:

  1. the pickers are separated in the UI, is there a better way to do it than my implementation?
  2. The most important one, it's visible all the time, I want something like the first image that you click, and it expands, or a popup is presented (not sure which UI is more apple style)

How can I fix the above?


Thank you

Answered by Claude31 in 417178022

What you need is a multi component Picker.


Seems you have to build it yourself in SwiftUI.


Some ways to do it here:

https://stackoverflow.com/questions/56567539/multi-component-picker-uipickerview-in-swiftui

Why not use DatePicker ?


Have a look here:

h ttps://www.hackingwithswift.com/books/ios-swiftui/selecting-dates-and-times-with-datepicker

I went over that, but If I choose .

hourAndMinute
it will show even the am/pm. Also I need the values in minutes and seconds, not time and a counter starting from 0 on the hours section, not a spiral of numbers
Accepted Answer

What you need is a multi component Picker.


Seems you have to build it yourself in SwiftUI.


Some ways to do it here:

https://stackoverflow.com/questions/56567539/multi-component-picker-uipickerview-in-swiftui

Picker with hours and minutes
 
 
Q