Skip to content

Instantly share code, notes, and snippets.

@yosshi4486
Created April 13, 2021 11:24
Show Gist options
  • Save yosshi4486/36ecc86ff691ba89eeebdaee50e6140a to your computer and use it in GitHub Desktop.
Save yosshi4486/36ecc86ff691ba89eeebdaee50e6140a to your computer and use it in GitHub Desktop.
カスタムView(タスクチェックボタン)のアクセシビリティ対応
// 画像のサイズよりもタップ領域を広げたいので、contentViewを別途設けており、それのアクセシビリティ要素にしたい
taskContentView.isAccessibilityElement = true
taskContentView.accessibilityLabel = NSLocalizedString("Task Status", comment: "")
taskContentView.accessibilityCustomActions = [
    UIAccessibilityCustomAction(name: NSLocalizedString("Toggle task status", comment: ""), actionHandler: { [weak self] (action) -> Bool in
self?.toggleDone(action)
return true
    })
]
// ステータスが切り替わった後にどこかで設定する
taskContentView.accessibilityValue = done ? NSLocalizedString("Done", comment: "") : NSLocalizedString("Not done", comment: "")
思ったより簡単にできた。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment