ios - UIDatePicker 在 iOS9 RTL 上翻转

标签 ios ios9 rtf uidatepicker picker

在 RTL 上显示 DatePicker - 时间模式时,我遇到了一个奇怪的问题。

我以编程方式显示日期选择器。 分钟应该在右边,小时在左边,在下图中你可以看到它被翻转了:

enter image description here

它发生在 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/

相关文章:

ios - Xcode 6 Beta UIWebView 无法读取 .rtf

ios - 在核心数据中创建关注者关注模型

iphone - 异常 'NSInvalidArgumentException' ,原因 : '-[AnnotationView setCoordinate:]: unrecognized selector sent to instance

ios - 如何快速将枚举存储到可变数组中

ios - 以编程方式创建一个在横向和纵向工作的 UIPickerView

c# - 如何使用 Qt Quick 显示富文本格式 (rtf)?

python - 使用 python 的 doc、docx 或 rtf 文件中的页数

ios - VoIP相当于Coretelephony

ios - 用于检查某个 iOS 应用程序是否由某个 Apple ID 购买的 Apple API

ssl - 模拟器中的应用程序传输安全