From 7141932f32267c78eca1a52dba05aeabb258f9ca Mon Sep 17 00:00:00 2001 From: Alex Wall Date: Thu, 16 Nov 2017 11:26:49 -0800 Subject: [PATCH] Implementing generic Accessibility labels and voice over for the various HUD content types --- PKHUD/HUD.swift | 28 ++++++++++++++++++++++++++++ PKHUD/PKHUD.swift | 1 + 2 files changed, 29 insertions(+) diff --git a/PKHUD/HUD.swift b/PKHUD/HUD.swift index 5e4b853..73a0e7c 100644 --- a/PKHUD/HUD.swift +++ b/PKHUD/HUD.swift @@ -44,6 +44,7 @@ public final class HUD { // MARK: Public methods, PKHUD based public static func show(_ content: HUDContentType, onView view: UIView? = nil) { PKHUD.sharedHUD.contentView = contentView(content) + PKHUD.sharedHUD.contentView.setAccessibilityProperties(for: content) PKHUD.sharedHUD.show(onView: view) } @@ -102,3 +103,30 @@ public final class HUD { } } } + +fileprivate extension UIView { + fileprivate func setAccessibilityProperties(for content: HUDContentType) { + self.accessibilityLabel = "Please wait." + switch content { + case .success: + self.accessibilityLabel = "Success!" + case .error: + self.accessibilityLabel = "Error!" + case .image(_), + .rotatingImage(_): + self.accessibilityLabel = "Image" + case .label(let title): + guard let label = title else { break } + self.accessibilityLabel = label + case .labeledSuccess(let title, let subtitle), + .labeledError(let title, let subtitle), + .labeledProgress(let title, let subtitle), + .labeledImage(_, let title, let subtitle), + .labeledRotatingImage(_, let title, let subtitle): + guard title != nil || subtitle != nil else { break } + self.accessibilityLabel = (title ?? "") + "\n" + (subtitle ?? "") + default: + self.accessibilityLabel = "Please wait." + } + } +} diff --git a/PKHUD/PKHUD.swift b/PKHUD/PKHUD.swift index 139e935..9f3a3fd 100644 --- a/PKHUD/PKHUD.swift +++ b/PKHUD/PKHUD.swift @@ -132,6 +132,7 @@ open class PKHUD: NSObject { } else { showContent() } + UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.container.frameView.content) } func showContent() {