I need a combined date & time picker in a Xamarin.Forms project, so I used a custom View & Renderer which works great on my iPhone 8 Plus test device. Unfortunately on an iPhone XS or 11 Pro (physical devices, both on 13.3) the picker does not render correctly - all the dates are greyed out, and time is completely invisible yet present (I can feel the 'clicks' when swiping up/down in the area where it would be). Unsurprisingly, the simulator for both those devices renders correctly. Full sample project along with screenshots from both devices on GitHub. Here's the relevant code from the renderer in case anything jumps out:
protected override void OnElementChanged(ElementChangedEventArgs<MyDatePicker> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
_datePicker.ValueChanged -= DatePickerOnValueChanged;
}
if (e.NewElement != null)
{
if (Control == null)
{
_datePicker = new UIDatePicker(new CGRect(
e.NewElement.Bounds.X,
e.NewElement.Bounds.Y,
e.NewElement.Bounds.Width,
e.NewElement.Bounds.Height
));
_datePicker.Mode = UIDatePickerMode.DateAndTime;
_datePicker.Date = (NSDate) Element.Date;
_datePicker.MaximumDate = (NSDate) Element.Date.AddDays(1);
_datePicker.MinimumDate = (NSDate) Element.Date.Subtract(TimeSpan.FromDays(5));
_datePicker.MinuteInterval = 1;
SetNativeControl(_datePicker);
}
_datePicker.ValueChanged += DatePickerOnValueChanged;
}
}
This issue was solved by the extremely knowledgable ColeX over on the Xamarin Forums. ColeX should really get the points for this, but I'm posting the answer here so that if anyone else searches for this issue on SO they will see a solution.
The root cause is dark mode on iOS when the app is not setup to render itself differently for light/dark mode. As a result the OS thinks it is rendering a date picker on a dark background, which it was not, and so it was effectively invisible. There are a few solutions mentioned, but the one that worked for me was add the following to Info.plist in the iOS project:
<key>UIUserInterfaceStyle</key>
<string>Light</string>