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".
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.
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.
let textField = UITextField()
textField.accessibilityTraits = UIAccessibilityTraitStaticText
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With