Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS9: UIDatePicker with datePickerMode of UIDatePickerModeTime only shows Hours, and no Minutes

I'm using Xcode beta 7 with the iOS9 simulator. Using a UIDatePicker with a datePickerMode of UIDatePickerModeTime only shows Hours, and not minutes.

See screenshot:

enter image description here

On iOS 7 and 8, obviously it works as expected, and shows both Hours and Minutes. Screenshot:

enter image description here

I really do not want to reinvent the wheel and roll my own time picker. Any ideas on why this might be happening and how to fix? I can't find anything on google.

thanks, Alex

like image 573
FranticRock Avatar asked Jul 29 '15 19:07

FranticRock


2 Answers

I encountered this after the public release of iOS 9.0 with a UIDatePicker using UIDatePickerModeDate in my tableview.

I hacked around it by changing the UIDatePicker mode right before it was displayed, and then changing it back to the desired one:

[myDatePicker setDatePickerMode:UIDatePickerModeDateAndTime];
[myDatePicker setDatePickerMode:UIDatePickerModeDate];

I'm guessing redrawing it solves the issue. For interest's sake I don't think it's actually an issue of not displaying the minutes but rather a bug in the subviews because this is what mine looked like:

UIDatePicker with white blocking space.

Inspecting using FLEX, this is part of the UIDatePicker that has a solid white background.

UIDatePicker bug in subviews.

like image 52
LordParsley Avatar answered Oct 21 '22 07:10

LordParsley


Found a useful description of this problem in the iOS 9 release notes - seems I should be reading these more carefully.

UIPickerView and UIDatePicker are now resizable and adaptive—previously, these views would enforce a default size even if you attempted to resize them. These views also now default to a width of 320 points on all devices, instead of to the device width on iPhone. Interfaces that rely on the old enforcement of the default size will likely look wrong when compiled for iOS 9. Any problems encountered can be resolved by fully constraining or sizing picker views to the desired size instead of relying on implicit behavior.

iOS 9 Release Notes

In my case all I had to do was remove all constraints on the UIDatePicker and then "Reset to Suggested Constraints". Rebuild and now all is well.

like image 32
Andrew Little Avatar answered Oct 21 '22 07:10

Andrew Little