Barış Deniz Sağlam
Barış Deniz Sağlam

Reputation: 131

Ignore accessibility label when selected in iOS?

I have a button with an accessibility label, say 'start'. When user focuses on it, voice over announces its label as expected. However, voice over announces the label again, when user double taps. I want to ignore this second announcement. I have checked Spotify's app, when clicked on 'play' button, its icon and label changes to 'pause' but voice over does not announce this change. How can I achieve the same behavior?

Upvotes: 1

Views: 1724

Answers (1)

XLE_22
XLE_22

Reputation: 5671

voice over announces the label again, when user double taps. I want to ignore this second announcement.

The fastest way to reach your goal is to override the accessibilityActivate function in a new button subclass:

class myButton: UIButton {

    override func accessibilityActivate() -> Bool {

        self.accessibilityLabel = ""

        return true
    }
}

Don't forget to redefine your accessibility label when the button action has lost the focus otherwise it will remain empty.
Use the UIAccessibilityFocus informal protocol in the myButton class as follows for instance:

override open func accessibilityElementDidLoseFocus() {
    self.accessibilityLabel = "yourPreviousLabelHere"
}

Upvotes: 1

Related Questions