Last active
November 1, 2017 18:27
-
-
Save KaneCheshire/46f84cf315c04062ff1b6a89fbb542ac to your computer and use it in GitHub Desktop.
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
import UIKit | |
protocol AccessibilityModel { | |
/// Whether the view should be an accessibility element | |
var isAccessibilityElement: Bool { get } | |
/// An optional accessibility label. This is read out by VoiceOver as | |
/// soon as the VoiceOver cursor focuses on the accessibility element. | |
/// | |
/// It is recommended to provide at least an accessibility label when | |
/// setting `isAccessibilityElement` to `true`. | |
var accessibilityLabel: String? { get } | |
/// An optional accessibility hint. This is read out by VoiceOver a | |
/// moment after the accessibility label has been read out (and traits if set). | |
/// | |
/// Accessibility hints are a great place to provide further information | |
/// about what the accessibility element represents or does. | |
/// | |
/// Do not put vital information in hints, because they can be disabled by | |
/// the user. | |
var accessibilityHint: String? { get } | |
/// An optional accessibility identifier. This is not read out by VoiceOver | |
/// but can be used to select and identify accessibility elements, useful | |
/// for UI testing. | |
var accessibilityIdentifier: String? { get } | |
/// Accessibility traits represent the various traits that characterise | |
/// an accessibility element. Accessibility traits can be combined, if | |
/// required, and are read out by VoiceOver before or after the accessibility label is | |
/// read out, depending on the trait. | |
/// | |
/// Set traits that make sense for the type of element you’re defining. | |
/// For example, a selected selectable cell could have the traits | |
/// UIAccessibilityTraitButton and UIAccessibilityTraitSelected. | |
/// and a UILabel could have the trait UIAccessibilityTraitHeader. | |
var accessibilityTraits: UIAccessibilityTraits { get } | |
} | |
/// Make each property optional by giving it a default implementation in | |
/// a protocol extension. | |
extension AccessibilityModel { | |
var isAccessibilityElement: Bool { | |
return false | |
} | |
var accessibilityLabel: String? { | |
return nil | |
} | |
var accessibilityHint: String? { | |
return nil | |
} | |
var accessibilityIdentifier: String? { | |
return nil | |
} | |
var accessibilityTraits: UIAccessibilityTraits { | |
return UIAccessibilityTraitNone | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment