Skip to content

Instantly share code, notes, and snippets.

@KaneCheshire
Created November 1, 2017 17:51
Show Gist options
  • Save KaneCheshire/dc55313d44387cf78125b8478e7dfe23 to your computer and use it in GitHub Desktop.
Save KaneCheshire/dc55313d44387cf78125b8478e7dfe23 to your computer and use it in GitHub Desktop.
class CustomCell: UICollectionViewCell {
@IBOutlet private var contentView: UIView! // Subview of `self`
@IBOutlet private var titleLabel: UIView! // Subview of `contentView`
@IBOutlet private var subtitleLabel: UIView! // Subview of `contentView`
@IBOutlet private var actionLabel: UIView! // Subview of `contentView`
private func setupAccessibility() {
contentView.isAccessibilityElement = true
let contentViewAccessibilityLabel = titleLabel.text + ", " + subtitleLabel.text
contentView.accessibilityLabel = contentViewAccessibilityLabel
actionLabel.isAccessibilityElement = true
actionLabel.accessibilityTraits = UIAccessibilityTraitButton
self.accessibilityElements = [contentView, actionLabel] // This determines the order as well
self.isAccessibilityElement = false // This is important!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment