Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change UITextField accessibility description

Is there a way to set the accessibility label of UITextField to be something other than the "text field". So instead of calling "text field", I want to name it "code verification field".

like image 821
yulia_samoylova Avatar asked Oct 30 '25 09:10

yulia_samoylova


2 Answers

My advice would be to not try to outsmart the system on build-in Voice Over outputs.

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

Feel free to use the accessibilityLabel and accessibilityHint to add more context to this field.

like image 199
Gesh Avatar answered Nov 01 '25 13:11

Gesh


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.

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"

textField.accessibilityHint = "code verification field"

accessibilityLabel would also work. The practical difference is that accessibilityLabel is read first, then textField.text (the text entered in the UITextField), then the 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.

like image 35
Mobile Dan Avatar answered Nov 01 '25 14:11

Mobile Dan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!