Search code examples
iosswiftvoiceoveruiaccessibility

How to make Voiceover to spell each letter in a word?


I have a text CPN34THX which should be read by voiceover as C N 3 4 T H X Is there any property to be set to UIAccessibility so that it can be read character by character?


Solution

  • iOS 13 and above

    You should use .accessibilitySpeechSpellOut or .accessibilitySpeechIPANotation. instead to make it spelling

    let code = "CPN34THX"
    let accessibleCode = NSMutableAttributedString(string: code, attributes:[.accessibilitySpeechSpellOut: true])
    myLabel.accessibilityLabel = accessibleCode
    

    iOS 12 and earlear

    Set the accessibilityLabel separately as you needed.

    let code = "CPN34THX"
    let accessibleCode = code.map(String.init).joined(separator: " ") // output: "C P N 3 4 T H X"
    myLabel.text = code
    myLabel.accessibilityLabel = accessibleCode
    

    For making it more pronounceable, make a string like this:

    myLabel.accessibilityLabel = "C^. P^. N^. 3. 4. T^. H^. X^."