Reputation: 187
I am giving a try to MonoTouch and MonoTouch.Dialog and was wondering what would be the best way to create a Time entry element for minutes and seconds only. The TimeElement only seems to support hours and minutes.
I am very new to the whole framework, so I am wondering if there a way to create a text entry element with sort of a "##:##" mask and use a numeric keypad to populate the minutes and seconds?
A cooler option would be to use a section that would take the user to a view with two "Picker Views" (rotating wheels) for minutes and seconds, but I am not there yet.
Thanks in advance
Upvotes: 1
Views: 320
Reputation: 33058
MonoTouch.Dialog's source code is available on Github (https://github.com/migueldeicaza/MonoTouch.Dialog/tree/master/MonoTouch.Dialog).
There, have a look at the implementation of the DateElement (https://github.com/migueldeicaza/MonoTouch.Dialog/blob/master/MonoTouch.Dialog/Elements.cs#L1827)
To get you a TimeElementMinutesSeconds
, all you have to do is (untested) abuse the count down mode. It will offer hours and minutes, but you can just interpret them as minutes and seconds:
public class TimeElementMinutesSeconds : DateTimeElement {
public TimeElementMinutesSeconds (string caption, DateTime date) : base (caption, date)
{
}
public override string FormatDate (DateTime dt)
{
DateTime dtLocal = GetDateWithKind (dt).ToLocalTime ();
return string.Format("{0:##}:{1:##}"dtLocal.Hours, dtLocal.Minutes);
}
public override UIDatePicker CreatePicker ()
{
var picker = base.CreatePicker ();
picker.Mode = UIDatePickerMode.CountDownTimer;
return picker;
}
}
If that doesn't get you near enough, you can create your own picker and return that instead.
Upvotes: 1