2020 SwiftUI & UI FrameworksAccessibility & Inclusion
WWDC20 · 22 min · SwiftUI & UI Frameworks / Accessibility & Inclusion
Accessibility design for Mac Catalyst
Make your Mac Catalyst app accessible to all — and bring those improvements back to your iPad app. Discover how a great accessible iPad app automatically becomes a great accessible Mac app when adding support for Mac Catalyst. Learn how to further augment your experience with support for mouse and keyboard actions and accessibility element grouping and navigation. And explore how to use new Accessibility Inspector features to test your app and iterate to create a truly great experience for everyone. To get the most out of this session, you should be familiar with Mac Catalyst, UIKit, and basic accessibility APIs for iOS. To get started, check out “Introducing iPad apps for Mac” and "Auditing your apps for accessibility."
Watch at developer.apple.com ↗Code shown on screen · 6 snippets
Ensuring selection automatically triggers when focus moves to a different cell
myTableView.selectionFollowsFocus = true Creating a keyboard shortcut
extension AppDelegate {
override func buildMenu(with builder: UIMenuBuilder) {
super.buildMenu(with: builder)
let shareCommand = UIKeyCommand(title: NSLocalizedString("Share", comment: ""),
action: #selector(Self.handleShareMenuAction),
input: "I",
modifierFlags: [.command])
let shareMenu = UIMenu(title: "",
identifier: UIMenu.Identifier("com.example.apple-samplecode.RoastedBeans.share"),
options: .displayInline,
children: [shareCommand])
builder.insertChild(shareMenu, atEndOfMenu: .edit)
}
@objc func handleShareMenuAction() {
}
} Responding to raw key codes
extension MyViewController {
override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
switch presses.first?.key?.keyCode {
case .keyboardLeftGUI:
// Handle command key pressed
case .keyboardB:
// Handle B key pressed
default:
}
}
} Adding accessibility labels to containers, such as UITableView and UICollectionView
tableView.accessibilityLabel = NSLocalizedString("Coffee list", comment: "") Making great accessibility labels that include state
extension RBListViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let data = tableData[indexPath.row]
let label = NSLocalizedString("Coffee list", comment: "")
let selectedLabel = NSLocalizedString("%@ selected", comment: "")
tableView.accessibilityLabel = label + ", " + String(format: selectedLabel, data.coffee.brand)
}
} Adding accessibility containers to improve the navigation experience
let stackView = UIStackView()
stackView.axis = .vertical
stackView.translatesAutoresizingMaskIntoConstraints = false
let locationsAvailable = viewModel.locationsAvailable
let titleLabel = UILabel()
titleLabel.font = UIFont.preferredFont(forTextStyle: .body).bold()
titleLabel.text = NSLocalizedString("Availability: ", comment: "")
stackView.addArrangedSubview(titleLabel)
for location in locationsAvailable {
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .body)
label.text = "• " + location
label.accessibilityLabel = location
stackView.addArrangedSubview(label)
}
stackView.accessibilityLabel = String(format: NSLocalizedString("Available at %@ locations", comment: ""), String(locationsAvailable.count))
stackView.accessibilityContainerType = .semanticGroup Resources
Related sessions
-
41 min -
38 min -
10 min -
10 min