Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 451
user3660992 Avatar asked Dec 14 '22 08:12

user3660992


1 Answers

I solved it by forcing forceRightToLeft on each date picker sub views.

Try the following and it should work:

override func viewDidLayoutSubviews() {
    for currentView in datePicker.subviews {
        currentView.semanticContentAttribute = .forceRightToLeft
    }
} 
like image 122
Itay Gardi Avatar answered Dec 21 '22 03:12

Itay Gardi