iOS 上的可访问时间标签

人气:885 发布:2022-10-16 标签: ios accessibility voiceover

问题描述

我正在尝试使我的 iPhone 应用程序可访问.其中一部分涉及为 NSDate 的时间和日期部分生成可访问的 VoiceOver 标签.如何以一种可访问的方式格式化 NSDate,以便在 VoiceOver 支持的所有语言中都能正常工作?

I am trying to make my iPhone app accessible. Part of it involves generating accessible VoiceOver labels for the time and date parts of an NSDate. How do I format an NSDate in an accessible way that will work correctly in all languages that VoiceOver supports?

推荐答案

NSDateFormatter 有一个名为 localizedStringFromDate:dateStyle:timeStyle: 的方法可以自动处理本地化.为每个日期和时间部分传递一个日期和 NSDateFormatterStyles.请注意,如果您想要一些带有画外音的读物,您可能需要不同的日期和时间样式.在大多数情况下,NSDateFormatterLongStyle 适用于日期(当您完全拼出月份时),而 NSDateFormatterShortStyle 适用于时间(因为它不包括秒).

NSDateFormatter has a method called localizedStringFromDate:dateStyle:timeStyle: that handles the localization automatically. Pass it a date and NSDateFormatterStyles for each the date and time portions. Note that you may want different styles for the date and time if you want something that reads nicely with voiceover. NSDateFormatterLongStyle works well for the date in most cases (as you get the month fully spelled out), while NSDateFormatterShortStyle works well for the time (as it doesn't include seconds).

更多信息:https://developer.apple.com/documentation/foundation/dateformatter/1415241-本地化字符串

373