Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make UITextField with VoiceOver read numbers as digits

Our App has a few UITextField where users enter alphanumeric input codes such as "AA149873A".

We'd like voice over to read these as "A A 1 4 9 8 7 2 A", but it instead reads the digits as a number: "One hundred and forty nine thousand, eight hundred and seventy three".

Is there some way to configure UITextField so that it knows its content shouldn't be thought of as numbers, but individual digits?

Thanks.

like image 499
Benjohn Avatar asked Jan 23 '26 01:01

Benjohn


1 Answers

We'd like voice over to read these as "A A 1 4 9 8 7 2 A", but it instead reads the digits as a number: "One hundred and forty nine thousand, eight hundred and seventy three".

The fastest wy to reach your goal is to add spaces between each character in the accessibilityValue of the UITextField as follows: 🤓

class AccessibilityTextField: UITextField {

    var _str: String?
    override var text: String? {
        get { return _str}
        set {
            _str = newValue!
            accessibilityValue = _str!.map{String($0)}.joined(separator: " ")
        }
    }

    convenience init() { self.init() }

    required init?(coder: NSCoder) { super.init(coder: coder) }
}

I didn't implement all the text field delegate stuff to test it ⟹ I created a blank project only with an UITextField adding a "BB0024FG" plain text and changed the text in the viewDidAppear of my view controller:

myTextField.text = "AA14987A"

In the end, VoiceOver spells out each character after another without reading out the initial plain text. 👍

Following this rationale, you have a way that let VoiceOver know that the UITextField content must be thought as individual digits. 😉

like image 146
XLE_22 Avatar answered Jan 26 '26 15:01

XLE_22