问题描述
我正在尝试使我的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).
更多信息:
:
这篇关于iOS上的可访问时间标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!