iOS上的可访问时间标签 [英] Accessible time labels on iOS

查看:63
本文介绍了iOS上的可访问时间标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的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/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html# // apple_ref / occ / clm / NSDateFormatter / localizedStringFromDate:dateStyle:timeStyle

这篇关于iOS上的可访问时间标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆