我有一个显示有变色指示器的 UITableViewCell
,但它会打开另一个应用程序而不是推送 View Controller (例如“访问我们的网站”,在 Safari 中打开)。我对可访问性和画外音的有限理解让我相信这应该被标记为“链接”而不是“按钮”,因为用户将离开应用程序。为此,我将 accessibilityTraits
设置为 .link
。
但是,一旦我在单元格上设置了披露指示器,该单元格就会显示为“访问我们的网站 - 按钮、链接”。
有没有办法保留披露指示符但从单元格中删除 .button
特征?
最佳答案
Is there a way to keep the disclosure indicator but remove the .button trait from a cell?
实现目标的一种方法是创建一个 UITableViewCell
子类,将 .link
值作为 accessibilityTraits
属性(property)。👍
class testCell:UITableViewCell {
override var accessibilityTraits: UIAccessibilityTraits {
get { return .link }
set { }
}
}
在你的 View Controller 中指定这个新的单元格类型将只读出它的链接属性,如下所示:🤓
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
}
根据这个原理,您可以将 UITableVewCell 的可访问性特征设置为“仅链接”。🥳🎊
如果需要,有一个 captivating website其中许多关于特征的信息都可以通过插图和代码片段获得。😉
关于ios - 如何将 UITableVewCell 的可访问性特征设置为仅 'link'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62662614/