Skip to content

Commit

Permalink
Implementing generic Accessibility labels and voice over for the vari…
Browse files Browse the repository at this point in the history
…ous HUD content types
  • Loading branch information
Alex Wall committed Nov 16, 2017
1 parent fadb681 commit 7141932
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions PKHUD/HUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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."
}
}
}
1 change: 1 addition & 0 deletions PKHUD/PKHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ open class PKHUD: NSObject {
} else {
showContent()
}
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.container.frameView.content)
}

func showContent() {
Expand Down

0 comments on commit 7141932

Please sign in to comment.