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

查看:19
本文介绍了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/documentation/foundation/dateformatter/1415241-本地化字符串

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

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