在 RTL 上显示 DatePicker - 时间模式时,我遇到了一个奇怪的问题。
我以编程方式显示日期选择器。 分钟应该在右边,小时在左边,在下图中你可以看到它被翻转了:
它发生在 iOS 9 及更高版本上。
我使用的代码:
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];
有什么建议吗?
最佳答案
我通过在每个日期选择器 subview 上强制使用 forceRightToLeft
解决了这个问题。
尝试以下操作,它应该有效:
override func viewDidLayoutSubviews() {
for currentView in datePicker.subviews {
currentView.semanticContentAttribute = .forceRightToLeft
}
}
关于ios - UIDatePicker 在 iOS9 RTL 上翻转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35577317/