Countdown timer picker with minutes and seconds

I am trying to replicate the timer picker from the Clock app, shown below, using SwiftUI.

DatePicker doesn't have a countDownTimer mode like UIDatePicker does, but then that doesn't show seconds even though the countDownDuration property is in seconds.

I am currently trying to use a custom UIPickerView with two components (minutes and seconds), all wrapped inside a UIViewRepresentable. This sort of works, but I can't seem to get the min and sec labels to be positioned where they are.

Any help on this matter would be much appreciated.

Answered by ForumsContributor in
Accepted Answer

UIDatePicker does not support configurations for the second unit. Please file a response with Feedback Assistant for this type of request.

That said, to achieve this, you'll have to manually add the label yourself onto the UIPickerView and figure out the position of your components to position the labels (They're aligned to the centerY so you just need to figure out the the x-position).

Hi  @BabyJ, I created a UIKit library to do exactly this! You can check it out here DurationPicker. It shouldn't be too difficult to wrap it in a UIViewRepresentable

Countdown timer picker with minutes and seconds
 
 
Q