如何为 UIPickerView 行设置 Voice Over 可访问性标签? [英] How to set the Voice Over accessibility label for UIPickerView rows?

查看:19
本文介绍了如何为 UIPickerView 行设置 Voice Over 可访问性标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的 Voice Over 的 UIPickerView 可访问,我注意到 UIPickerViewAccessibilityDelegate 协议相当不完整.它只允许您为 pickerView 组件指定标签和提示,而不是组件内的行.(它也有一个错误,它的 pickerView:accessibilityLabelForComponent: 方法没有在它的 pickerView 参数中传递 UIPickerView*,而是一个 UIAccessibilityPickerComponent !)

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?

我正在尝试创建一个显示时间、小时、分钟、秒的选择器视图.我无法让 datePicker 做到这一点.但是,如果每一行都可以在配音中说3 小时"而不是 3 小时,那就太好了.如果我必须将可见标签设置为我希望配音读出的内容,那么我不确定标签将适合显示这一点,即.

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 小时 35 分 20 秒

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.

干杯

推荐答案

如果你正在实现 UIPickerViewDelegatepickerView:viewForRow:forComponent:reusingView: 方法作为方式要填充 UIPickerView 组件,您可以通过在从该方法返回的 UIView 上设置 accessibilityLabel 来为每一行实现自定义辅助功能标签.

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.

请注意,在我使用 pickerView:titleForRow:forComponent: 填充 UIPickerView 的情况下,我没有成功让 VoiceOver 读取自定义辅助功能标签 - 甚至设置 accessibilityLabel 在返回的 NSString(在其他一些上下文中确实有效,比如为 UITableView 索引设置辅助功能标签)没有改变 VoiceOver 的发音.因此,如果您想自定义 VoiceOver(或切换控制)为 UIPickerView 行说话的唯一方法是使用 pickerView:viewForRow:forComponent:reusingView:,而不是其他任何 2候选方法,用于填充 UIPickerView 行.

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.

但是,我仍然建议您重新考虑您正在做的事情是否可取.当 VoiceOver(或切换控制)用户到达组件时,例如使用 accessibilityLabel分钟",他们知道他们是分钟,因为 VoiceOver 读取例如分钟,19",所以在调整数值时,他们不需要再听到20分钟",21分钟";20"和21"就足够了,用户可以记住上下文(例如现在我在几分钟内,所以让我们将其调整为 45").

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

这篇关于如何为 UIPickerView 行设置 Voice Over 可访问性标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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