Reputation: 221
I'm trying to get a 24 hour timepicker on iOS so that I can use it to insert a duration.
On android I got what I wanted by using a custom renderer. On iOS I also used a custom renderer (see code below) as I had found on the internet. The problem is that it only views the picker dialog in 24 hours, not the set time.
[assembly: ExportRenderer(typeof(Xamarin.Forms.TimePicker), typeof(CustomTimePicker))]
namespace IsalaSportmonitor.iOS.View.Controls
{
class CustomTimePicker : TimePickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
{
base.OnElementChanged(e);
var timePicker = (UIDatePicker)Control.InputView;
timePicker.Locale = new NSLocale("no_db");
}
}
}
Upvotes: 2
Views: 944
Reputation: 129
Try to check this:
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using PersonalTrainer.iOS.View.Controls;
[assembly: ExportRenderer (typeof (TimePicker), typeof (TimePicker24HRenderer))]
namespace YourNamespace.iOS.View.Controls {
public class TimePicker24HRenderer : TimePickerRenderer {
protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e) {
base.OnElementChanged(e);
var timePicker = (UIDatePicker)Control.InputView;
timePicker.Locale = new NSLocale("no_nb");
}
}
}
Upvotes: 3