简体   繁体   English

更改UITextField可访问性描述

[英]change UITextField accessibility description

Is there a way to set the accessibility label of UITextField to be something other than the "text field". 有没有办法将UITextField的可访问性标签设置为“文本字段”以外的其他标签。 So instead of calling "text field", I want to name it "code verification field". 因此,我不想调用“文本字段”,而是将其命名为“代码验证字段”。

My advice would be to not try to outsmart the system on build-in Voice Over outputs. 我的建议是不要试图在内置Voice Over输出上超越系统。

"Text field is editing" is to a blind user the audible equivalent to "This item is selected and there is a blinking cursor in it". “文本字段正在编辑”对于盲人用户来说,听觉相当于“此项目被选中并且其中有一个闪烁的光标”。

Same as you are unlikely to remove/change the blinking cursor from your UITetxtField you shouldn't try to remove/change that built in output. 与您不太可能从UITetxtField中删除/更改闪烁光标相同,您不应尝试删除/更改内置输出。

Feel free to use the accessibilityLabel and accessibilityHint to add more context to this field. 您可以随意使用accessibilityLabelaccessibilityHint为此字段添加更多上下文。

How to Quiet "Text Field" & Options to Replace It 如何安静的“文本字段”和替代它的选项

I posted a related answer that illustrates a few ways to stop VoiceOver from announcing "text field" for a UITextField. 我发布了一个相关的答案 ,说明了阻止VoiceOver宣布UITextField的“文本字段”的几种方法。

This is the a code excerpt from that answer. 这是该答案的代码摘录。

Quieting "Text Field" 平息“文本字段”

let textField = UITextField()
textField.accessibilityTraits = UIAccessibilityTraitStaticText

Replacement Text 替换文字

You could use the accessibilityHint for the alternate control name you want "code verification field" 您可以使用accessibilityHint作为您想要的“代码验证字段”的备用控件名称

textField.accessibilityHint = "code verification field"

accessibilityLabel would also work. accessibilityLabel也可以。 The practical difference is that accessibilityLabel is read first, then textField.text (the text entered in the UITextField), then the accessibilityHint . 实际的区别是首先读取accessibilityLabel ,然后是textField.text (在UITextField中输入的文本),然后是accessibilityHint

The following is read as: "label, text, (short pause...) hint" 以下内容读作:“标签,文字,(短暂暂停...)提示”

textField.accessibilityTraits = UIAccessibilityTraitStaticText
textField.accessibilityLabel = "label"
textField.text = "text"
textField.accessibilityHint = "hint"

You can find out more about UIAccessibility Element properties in Apple's API reference . 您可以在Apple的API参考中找到有关UIAccessibility Element属性的更多信息。

I believe you have to set the field's accessibilityLabel property (part of the UIAccessibility protocol). 我相信你必须设置字段的accessibilityLabel属性( UIAccessibility协议的一部分)。 Perhaps you also have to play around with the accessibilityTraits property to override the UIKit labeling. 也许您还必须使用accessibilityTraits属性来覆盖UIKit标签。

As per my knowledge, Voice over reads the accessibilityLabel, accessibilityHint, "text field is editing" when it is a textfield. 据我所知,当它是一个文本字段时,Voice over读取accessibilityLabel,accessibilityHint,“文本字段正在编辑”。 There is no way to change this until you change the trait. 在更改特征之前无法更改此设置。

YOU can change the trait to UIAccessibilityTraitNone , so that it does not read as "textfield is editing". 您可以将特征更改为UIAccessibilityTraitNone ,因此它不会读作“textfield is editing”。

Updating this question with some current advice. 用一些当前的建议更新这个问题。

It is not appropriate to override UIKit's default accessibility handling beyond the accessibility properties it provides. 除了它提供的可访问性属性之外,覆盖UIKit的默认可访问性处理是不合适的。 Use accessibilityLabel, accessibilityHint, accessibilityTraits, etc. 使用accessibilityLabel,accessibilityHint,accessibilityTraits等。

UITextField has built in accessibility and handles role and state information to provide a consistent and robust experience to VoiceOver users. UITextField内置可访问性并处理角色和状态信息,为VoiceOver用户提供一致且强大的体验。 You can suppress certain VoiceOver announcements using accessibilityTraits, but that does not mean that you should. 您可以使用accessibilityTraits禁止某些VoiceOver公告,但这并不意味着您应该这样做。

The most appropriate thing to do in such a situation is to simply set a suitable label: myTextField.accessibilityLabel = "Code verification" 在这种情况下最合适的做法是简单地设置一个合适的标签:myTextField.accessibilityLabel =“Code verification”

This will result in VoiceOver announcing, "Code verification, text field, is editing", which is what users will expect to hear. 这将导致VoiceOver宣布“代码验证,文本字段,正在编辑”,这是用户期望听到的内容。

Note that accessibilityHint can be turned off by users, so this property should not be used for essential messaging or information. 请注意,accessibilityHint可以由用户关闭,因此不应将此属性用于基本消息传递或信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM