diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 186c24c8..5a189cb5 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -14,7 +14,7 @@ public typealias ActionBlock = () -> Void @objcMembers open class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol, MFButtonProtocol { //------------------------------------------------------ - // MARK: - General Properties + // MARK: - Properties //------------------------------------------------------ public var makeWholeViewClickable = false @@ -63,6 +63,7 @@ public typealias ActionBlock = () -> Void numberOfLines = 0 lineBreakMode = .byWordWrapping translatesAutoresizingMaskIntoConstraints = false + isAccessibilityElement = false let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped(_:))) tapGesture.numberOfTapsRequired = 1 @@ -152,7 +153,7 @@ public typealias ActionBlock = () -> Void } //------------------------------------------------------ - // MARK: - Functions + // MARK: - Style //------------------------------------------------------ @objc public static func setLabel(_ label: UILabel?, withHTML html: String?) { @@ -272,12 +273,6 @@ public typealias ActionBlock = () -> Void } } - - - //------------------------------------------------------ - // MARK: - Methods - //------------------------------------------------------ - @objc public func styleH1(_ scale: Bool) { MFStyler.styleLabelH1(self, genericScaling: false) setScale(scale) @@ -567,3 +562,49 @@ extension UITapGestureRecognizer { return NSLocationInRange(indexOfGlyph, targetRange) } } + +// MARK: - Accessibility +extension Label { + + override open func accessibilityActivate() -> Bool { + let point = accessibilityActivationPoint + + return true + } + + open override func accessibilityElementDidBecomeFocused() { + <#code#> + } + + open override func accessibilityElementCount() -> Int { + return accessibleClauses.count + } + + open override func accessibilityElement(at index: Int) -> Any? { + return accessibleClauses[index] + } + + open override func index(ofAccessibilityElement element: Any) -> Int { + return accessibleClauses.firstIndex(of: element as! UIAccessibilityElement)! + } + + var accessibleClauses: [UIAccessibilityElement] { + + var elements = [UIAccessibilityElement]() + + for clause in clauses { + + let element = UIAccessibilityElement(accessibilityContainer: self) + let rect = CGRect(x: 10, y: 10, width: 100, height: 30) + element.accessibilityFrame = rect +// element.accessibilityFrame = convert(conceptualSize(range: clause.range)!, to: nil) + element.accessibilityFrameInContainerSpace = rect + element.accessibilityLabel = "Testing" + element.accessibilityTraits = .button + element.isAccessibilityElement = true + elements.append(element) + } + accessibilityElements = elements + return elements + } +}