I want to make a custom keyboard perform like the iOS software keyboard with regards to accessibility. When a button-press adds a letter to a UITextField, the letter should be spoken by VoiceOver in the ‘added character tone‘. When a button-press deletes a letter from a UITextField, the letter should be spoken by VoiceOver in the ‘deleted character tone’.
Here is what I attempted:
- Created a UITextField in the view controller, in the storyboard.
- Created two UIButtons labeled ‘Type’ and ‘Backspace’ in the view controller, in the storyboard.
- Set the accessibility traits for both UIButtons to Keyboard Key.
- Hooked the storyboard UITextField up to an IBOutlet UITextField instance, textField.
- Hooked the storyboard ‘Type’ UIButton up to an IBAction, -type.
- Hooked the storyboard ‘Backspace’ UIButton up to an IBAction, -backspace.
- Implemented -type as:
[[self textField] insertText:@"a"];
. - Implemented -backspace as:
[[self textField] deleteBackward];
. - Made textField the first responder.
I also tried the same thing, moving the buttons into a UIView that was set as textField’s inputView.
The characters are properly added to and removed from the text field, but they are not spoken by VoiceOver. How can I make this work?
EDIT:
The hardware keyboard speaks correctly. It is only the custom software keyboard that is not speaking as it should.
textField:shouldChangeCharactersInRange:replacementString:
when these keys are pressed? – David Rönnqvist