Accessible time labels on iOS

后端 未结 2 938
轻奢々
轻奢々 2021-01-03 23:42

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 form

2条回答
  •  旧巷少年郎
    2021-01-03 23:51

    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).

    More information: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html#//apple_ref/occ/clm/NSDateFormatter/localizedStringFromDate:dateStyle:timeStyle:

提交回复
热议问题