Custom actions help remove clutter in your app.
If we have a table with multiple cells and each cell has multiple buttons, by default voiceover will read each button for each cell.
Voiceover should only focus on the cell content, and provide custom actions instead.
Old way:
override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
get {
let myAction = UIAccessibilityCustomAction(
name: "Custom Action",
target: self,
selector: #selector(handleAction(_:)
)
return [myAction]
}
set {}
}
@objc func handleAction(_ action: UIAccessibilityCustomAction) -> Bool {
var success = false
// action logic
return success
}New way:
override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
get {
let actions = [UIAccessibilityCustomAction]()
let myAction = UIAccessibilityCustomAction(name: "Custom Action") {
(customAction: UIAccessibilityCustomAction) -> Bool in
var success = false // action logic return success
}
actions.append(myAction) return actions
}
set {}
}