Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add accessibility label for VoiceOver at Swipe Action Configuration for Row?

Tags:

I'm creating an iOS App using Swift 4 and I'm not using Storyboards. To delete a row from the Table View Controller the user swipe left the row and then click the Delete Button.

Here is the code I'm using to implement that (no external libraries have been used):

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    self.isAccessibilityElement = true
    self.accessibilityLabel = "Delete row"


    let deleteAction = UIContextualAction(style: .normal , title: "DELETE") { (action, view, handler) in

        self.removeRowFromMyList(indexPath: indexPath.row)

        MyListController.stations.remove(at: indexPath.row)
        self.tableView.deleteRows(at: [indexPath], with: .automatic)

        self.tableView.setEditing(false, animated: true)
        self.tableView.reloadData()
    }
    let swipeAction = UISwipeActionsConfiguration(actions: [deleteAction])
    swipeAction.performsFirstActionWithFullSwipe = false

    return swipeAction
}

I did check other questions and none of them address that. Please don't hesitate to comment here for any other information you need to know to solve this issue. Thanks :)

like image 607
Pavlos Avatar asked Nov 28 '17 10:11

Pavlos


People also ask

What is accessibility label in IOS?

The label is a very short, localized string that identifies the accessibility element, but does not include the type of the control or view. For example, the label for a Save button is “Save,” not “Save button.” By default, standard UIKit controls and views have labels that derive from their titles.

What is Accessibilitylabel?

On Android, accessible={true} property for a react-native View will be translated into native focusable={true}. accessibilityHint An accessibility hint helps users understand what will happen when they perform an action on the accessibility element when that result is not clear from the accessibility label.

How does swift implement accessibility?

Start by enabling VoiceOver in the Settings app, under General > Accessibility. If you haven't used VoiceOver before, you can scroll around using three-finger swipes, select elements by tapping on them, and activate controls by double tapping. Make sure all elements have accessibility labels.


2 Answers

Using Accessibility Custom Action from UIAccessibility by Apple

You just need to set Accessibility Custom Action:

cell.accessibilityCustomActions = [UIAccessibilityCustomAction(name: "Delete", target: self, selector: #selector(theCustomAction))]


@objc private func theCustomAction() -> Bool {
    //Do anything you want here
    return true
}

Update:

So I did recreate the project but this time I was using Storyboards (I wasn't the last time) and I imported from Cocoapods the SwipeCellKit Library and I followed their documentation and VoiceOver was working perfectly fine with deleting a cell from them indexPath.row with no problem.

like image 95
Pavlos Avatar answered Oct 11 '22 15:10

Pavlos


  1. When Voice Over is turned on and the UITableViewCell is in focus, Voice Over would announce "Swipe Up or Down to Select a Custom Action, then double tap to activate"

  2. If the user follows the above mentioned instruction, the user would be able to select one of the many actions available and double tap to activate it

  3. After performing the action, Voice Over would announce "Performed action "

Note:

  • Advantage with using standard controls is that accessibility is mostly handled for you.
  • You don't have to worry about it breaking with newer versions of iOS
  • If system provides built in functionality then go with it.
like image 29
user1046037 Avatar answered Oct 11 '22 16:10

user1046037