I'm implementing VoiceOver and I have problems on iOS 13.x with the text read on datepicker values. It seems like the accessibily string are not changed after the datepicker locale is changed. The column for months has the strings from US days, It says fünf von dreissig (5 from 30) after the April is selected, it should says 4 from 12.
On datepicker I set
datePicker.locale = Locale.init(identifier: "de_DE")
and datePicker.calendar = Calendar.init(identifier: Calendar.Identifier.gregorian)
. I also tried to set datePicker.accessibilityLanguage = "de-DE"
.
Any ideas?
Any ideas?
It's impossible to modify the locale inside an UIDatePicker
for VoiceOver. 😱
The language that will be taken into account is the selected one in the device settings.
EXPLANATION 🤯
The UIDatePicker
element is a wrapper containing many other elements that the VoiceOver user can interact with (year, month and day in your case).
As is, the UIDatePicker
isn't itself accessible because a view and its subviews can't be both accessible alltogether.
It's correct to write datePicker.accessibilityLanguage = "de-DE"
because UIControl conforms to the UIAccessibility informal protocol but VoiceOver won't analyze it (the parent view isn't accessible here).
The views defining the date are the only ones to be accessible and interpreted by VoiceOver as adjustable
elements but they can't be reached in development unfortunately.
The UIDatePicker
is a kind of a black box that allows few operations but prevents from accessing its subviews for instance... that could be a good lead of investigation here. 😞
SOLUTION 🤓
In your use case, nothing can be customized with the UIDatePicker
but, to reach your goal with VoiceOver, I recommend to use a UIPickerView
as suggested on the Apple website:
If you want to handle the selection of arbitrary items from a list, use a UIPickerView object.
UIPickerView
object with different wheels.adjustable
trait to allow the VoiceOver user to select an element in the list.NSAttributedString
in order to add an attribute that will specify the language or use the accessibilityLanguage
as you did, both should be efficient.It's a lot of work in comparison to the turn-key UIDatePicker
object but I think you'll be able to get your purpose by adapting the language for VoiceOver in your date picker following this rationale. 😉