Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessible time labels on iOS

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?

like image 433
Martijn Avatar asked Nov 16 '12 14:11

Martijn


1 Answers

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/documentation/foundation/dateformatter/1415241-localizedstring

like image 141
Ben Swanson Avatar answered Sep 21 '22 14:09

Ben Swanson