Search code examples
c#xamarinuidatepickerios14

UIDatePicker stopped working Xamarin IOS14


Since I have updated to Xcode 12 and VS (2019 8.7.8 build 4) on my mac and updated Xamarin to the latest version (Xamarin.iOS 14.0.0.0), I find I am unable to use UIDatePicker.

DatePicker

Looking at the documentation, https://developer.apple.com/documentation/uikit/uidatepicker I need to set Style and maybe preferredDatePickerStyle but neither are these are properties I can set in the (Xamarin) code.

Has anyone found a way to get past this to enable the date to be selected?


Solution

  • It will work once we set the preferredDatePickerStyle and sizeToFit, Sample code is given below.

    _datePicker = new UIDatePicker(new CGRect(0, 30, 0, 0));
    _datePicker.AutoresizingMask = UIViewAutoresizing.FlexibleRightMargin;
    _datePicker.Frame = new CGRect(_datePicker.Frame.Location, new CGSize(300, _datePicker.Frame.Size.Height));
    _datePicker.Mode = _datePickerMode;
    _datePicker.Date = (NSDate)_defaultDate;
    _datePicker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels; //Add this in ios14
    _datePicker.SizeToFit(); //Add this in ios14