I am using Xamarin Forms and somewhere in my application, I need the user to be able to enter a time in the format HH:mm:ss. So, basically I need a control like this one:
By using a custom iOS render, I've been able to remove the AM/PM part from the TimePicker to achieve something like this:
Here's my renderer code:
public class TimePickerSecondsRenderer : TimePickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
{
base.OnElementChanged(e);
var timePicker = (UIDatePicker)Control.InputView;
timePicker.Locale = new NSLocale("CA");
}
}
It's a small step in the right direction I suppose, but I'm really at loss when it comes to adding a third column for the seconds, as well as the labels for each column.
I took a look at this post but it doesn't really help me so far.
Did anyone managed to achieve that kind of control with their Xamarin Forms project? Would you mind sharing some pointers?
I finally got a working implementation. Here's the result:
The only downside is that the labels "hr", "min", and "sec" are in their own column. As such, there is a bounce effect if the user tries to interact with them. I'll try to see if I can improve it later.Suggestions welcome!And, of course, the code (if it can be of use to someone):
The renderer
Custom bindable picker class
XAML usage
Where SelectedTime is your ViewModel property used for binding. Must be of type TimeSpan.
I'm sure it can be improved, so comment away if you have suggestions.
UPDATE
I've updated the renderer code.
Note that this code is dependent on XForms (https://github.com/XLabs/Xamarin-Forms-Labs) to get the device screen size, because that's the framework that I'm using for my project, but it can easily be modified.