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:
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 ?
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With