Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can set UITableVewCell's accessibility traits to be 'link' only?

I have a UITableViewCell that is displayed with a discolor indicator but opens another application rather than pushing a view controller (for example 'Visit our Website', opening in Safari). My limited understanding of accessibility and voiceover leads me to believe this should be marked as a 'link' rather than a 'button', since the user will be leaving the app. To accomplish this I set the accessibilityTraits to .link.

However, as soon as I set the disclosure indicator on the cell, the cell is read as 'Visit our Website - button, link".

Is there a way to keep the disclosure indicator but remove the .button trait from a cell?

like image 640
Ben Packard Avatar asked Nov 01 '25 04:11

Ben Packard


1 Answers

Is there a way to keep the disclosure indicator but remove the .button trait from a cell?

One way to reach your goal is to create a UITableViewCell subclass with the .link value as accessibilityTraits property.👍

class testCell:UITableViewCell {

    override var accessibilityTraits: UIAccessibilityTraits {
        get { return .link }
        set {  }
    }
}

Indicating this new cell type in your view controller will read out only its link property as follows:🤓

override func tableView(_ tableView: UITableView, 
                        cellForRowAt indexPath: IndexPath) -> testCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", 
                                             for: indexPath) as! testCell

    cell.textLabel?.text = "Visit our Website"
    return cell
}

Following this rationale, you can set UITableVewCell's accessibility traits to be 'link' only.🥳🎊

If need be, there's a captivating website where many informations about the traits are available with illustrations and code snippets.😉

like image 113
XLE_22 Avatar answered Nov 02 '25 18:11

XLE_22