Created
April 13, 2021 11:24
-
-
Save yosshi4486/36ecc86ff691ba89eeebdaee50e6140a to your computer and use it in GitHub Desktop.
カスタムView(タスクチェックボタン)のアクセシビリティ対応
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 画像のサイズよりもタップ領域を広げたいので、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