如何解决可访问性列表读取 iOS Swift
有什么方法可以让 tableview 读取为可访问性列表,同时将整个重点放在 tableview 上? 例如:我有一个像
这样的列表- 艺术
- 球
- 汽车
- 狗
所以我希望无障碍阅读器阅读为“4 项艺术的第 1 项,4 个球的第 2 项,......等”
解决方法
是的,您可以,但您必须手动实现。
您可以为您的单元创建某种模型,用于配置它。 您需要将表格视图的总行数传递给每个单元格的配置。
struct CellConfig {
let title: String
private let count: Int
init(title: String,count: Int) {
self.title = title
self.count = count
}
}
您实际上可以扩展功能,通过像这样传递当前的 CellConfig
来让 IndexPath
返回正确的无障碍标签:
struct CellConfig {
...
func axLabel(for indexPath: IndexPath) -> String {
let currentElement = indexPath.row + 1
return "Item \(currentElement) of \(count). \(title)."
}
}
因此,当从您的委托方法返回您的单元格时:
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard indexPath.row < items.count else { return UITableViewCell() }
let item = items[indexPath.row] // The array here holds all the configs of every cell.
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell",for: indexPath) as? UITabelViewCell
cell?.titleLabel.text = item.title
cell?.accessibilityLabel = item.axLabel(for: indexPath)
return cell ?? UITableViewCell()
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。