How to set the Voice Over accessibility label for UIPickerView rows?

∥☆過路亽.° 提交于 2019-12-10 16:47:14

问题


I'm trying to make a UIPickerView of mine Voice Over accessible, I've noticed that the UIPickerViewAccessibilityDelegate protocol is rather incomplete. It only allows you to specify labels and hints for pickerView components, not the rows within the components. (it also has a bug that its pickerView:accessibilityLabelForComponent: method doesn't pass a UIPickerView* in it's pickerView parameter, it's a UIAccessibilityPickerComponent instead!)

So i'm wondering now, is there any way at all to set custom accessibility labels for the rows of my picker, or is it only possible to read out the actual picker row values as displayed on the screen?

I'm trying to do a picker view that shows time on it, hours, minutes, seconds. I couldn't get the datePicker to do this. But it'd be nice if each row could in voice over say something like "3 hours" instead of just 3. If I have to set the visible labels to what I want the voice over to read out then I'm not sure the labels are going to fit to show this, ie.

15 hours 35 minutes 20 seconds

is quite a lot to fit on the screen in english, not sure how big it'll grow when localised.. hence the ideal of being able to set labels for each row.

Cheers


回答1:


If you are implementing the pickerView:viewForRow:forComponent:reusingView: method of UIPickerViewDelegate as the way to populate the UIPickerView components, you can achieve custom accessibility label for each row by setting accessibilityLabel on the UIView you are returning from that method.

Note that I wasn't successful at making VoiceOver read custom accessibility label in cases where I populate the UIPickerView using pickerView:titleForRow:forComponent: - even setting accessibilityLabel on the returned NSString (which does work in some other contexts, like setting accessibility labels for UITableView indexes) did not change what VoiceOver pronounces. So it seems the only way to go if you want to customize what VoiceOver (or Switch Control) speaks for a UIPickerView row is to use pickerView:viewForRow:forComponent:reusingView:, not any of the other 2 candidate methods, to populate the UIPickerView rows.

However, I still recommend you to reconsider whether what you are doing is desirable. When VoiceOver (or Switch Control) user arrives on the component, say e.g. with accessibilityLabel "Minutes", they know they are on minutes, because VoiceOver reads e.g. "Minutes, 19", and so when adjusting the value, they don't need to hear again "20 minutes", "21 minutes"; "20" and "21" quite suffices, the user can remember the context (e.g. "now I am on minutes, so let's adjust it to 45").



来源:https://stackoverflow.com/questions/30790992/how-to-set-the-voice-over-accessibility-label-for-uipickerview-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!