10

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

FranticRock
  • 3,233
  • 1
  • 31
  • 56
  • Any response from Apple? I'm still seeing this issue in Beta 5. Do you know (perhaps from the ticket you created) if we'll be able to expect a solution before iOS 9.0 drops? It'd certainly be nice to allow our QA teams to test our iOS 9 builds/compatibility before the public gets it. – u2Fan Aug 24 '15 at 14:56
  • http://stackoverflow.com/a/32751985/6034101 works for me for this problem..Thanks. – Ashwini Mar 08 '16 at 11:54

6 Answers6

23

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.

LordParsley
  • 3,808
  • 2
  • 30
  • 41
8

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.

Andrew Little
  • 6,606
  • 1
  • 25
  • 15
  • Reset to suggested did not work for me (DatePicker is inside a TableViewCell). I did Equal widths to superview, fixed height, leading space and top space to superview and boom - everything looked good. – nickdnk Nov 05 '15 at 14:27
  • This is the solution that worked for me. Added Leading, Trailing, Top, Bottom constraints in my Nib file, and it works. – FranticRock Nov 27 '15 at 21:34
2

I had an issue when upgrading Xcode to 7.0.

When the UIDatePicker was displayed the middle portion was blank, as per LordParsley's answer.

The height of the UIDatePicker for iOS 9 is 216; whereas earlier versions the height is 162, and forcing the height to 162 resolved the issue.

Since my view is defined within a storyboard, I setup a height constraint on the UIDatePicker and set the height to 162 for iOS versions < 9.0, within the view's viewDidLoad.

- (void) viewDidLoad {
    [super viewDidLoad];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
        //
        // NOTE: iOS 9, or Xcode 7, now sets UIDatePicker height at 216; whereas,
        // iOS 8, or Xcode 6.x, set it at 162.
        //
        // If the height is left at 216, then on iOS 7.1, the middle portion of the
        // UIDatePicker control is missing.  Setting the hieght to 162 fixes the issue
        // within this application.
        //
        // UIDatePicker frame cannot be used to adjust the size, therefore use a
        // height contraint to change the size.
        //
        self.dateHeightConstraint.constant = 162;
    }
}
Martyn Davis
  • 625
  • 1
  • 10
  • 16
  • 1
    You can have height of 216 on iOS 8. So it's not about running iOS version. Maybe about Xcode version and iOS Base SDK, yes. – Cœur Jan 19 '16 at 01:33
  • Thanks @Cœur for the clarification with respect to iOS 8. So it is more to do with dev tools than run time. – Martyn Davis Jan 20 '16 at 22:48
1

@LordParsley solution did the trick.

Just some additional details:

I notice it occurs on iPhone 5 series and not on iPhone 6/6 plus with leading and trailing constraints. Apparently the bug only appears when its frame width is 320. Probably its a miscalculation of picker subviews that causes the overlaps. This is quite funny because Apple is the one who set the default value and yet they've oversaw the issue.

Anyways I hope this gets resolved with iOS 9.1 which is now in beta.

Teffi
  • 2,498
  • 4
  • 21
  • 40
1

I have same issue when running my app in iOS 9, my app using UIDatePicker in .xib file. I resolved this problem by add it in code behind:

UIDatePicker* picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 320, 162)];
[self.view addSubview:picker];

I think, this's problem with new font San Francisco (the font is big than Helvetica) and .xib file. Hope this help. Thank!

Franken
  • 39
  • 5
0

On iPhone 5S iOS 9.1 my month names are truncated when I display the UIDatePicker. I fixed this problem by setting a local property as follows:

NSLocale *uk = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setLocale:uk];
[_backdateDatePicker setCalendar:cal];
John John
  • 71
  • 2
  • 5