Search code examples
iosios9rtfuidatepickerpicker

UIDatePicker Flips on iOS9 RTL


I have a weird issue when displaying a DatePicker - Time mode on RTL.

Im displaying the date picker programmatically. Minutes should be on the right side, and hours on the left, and on the following image you can see it's flipped:

enter image description here

It happens on iOS 9 and above.

The code I'm using:

UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, self.view.frame.size.width, 216)];
datePicker.tag = tag;
[datePicker setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
[datePicker setDatePickerMode:UIDatePickerModeTime];
[datePicker setBackgroundColor:[UIColor whiteColor]];
[datePicker addTarget:self action:@selector(changeDate:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];

Any suggestions ?


Solution

  • I think this is a side-effect of your setting .ForceRightToLeft on UIView's appearance proxy.

    If that's the case, please note that this is not a supported use case. Your app should only be in RTL if it's:

    a) localized into an RTL language, and

    b) the device's system language is set to that language.