From 0248d311b1a6e0c558f371690d920e0494f09379 Mon Sep 17 00:00:00 2001 From: Jordan Hipwell Date: Sun, 30 Apr 2017 18:22:49 -0600 Subject: [PATCH] Make color wheel, brightness view, and selected color view accessible --- Source/BrightnessView.swift | 4 ++++ Source/ColorWheel.swift | 4 ++++ Source/SelectedColorView.swift | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/Source/BrightnessView.swift b/Source/BrightnessView.swift index 0afd876..77fcedd 100755 --- a/Source/BrightnessView.swift +++ b/Source/BrightnessView.swift @@ -25,6 +25,10 @@ class BrightnessView: UIView { init(frame: CGRect, color: UIColor) { super.init(frame: frame) + // Enable direct interaction for VoiceOver users + self.isAccessibilityElement = true + self.accessibilityTraits |= UIAccessibilityTraitAllowsDirectInteraction + // Init the point at the correct position point = getPointFromColor(color) diff --git a/Source/ColorWheel.swift b/Source/ColorWheel.swift index c6cff6a..b320fdc 100755 --- a/Source/ColorWheel.swift +++ b/Source/ColorWheel.swift @@ -42,6 +42,10 @@ class ColorWheel: UIView { self.color = color + // Enable direct interaction for VoiceOver users + self.isAccessibilityElement = true + self.accessibilityTraits |= UIAccessibilityTraitAllowsDirectInteraction + // Layer for the Hue/Saturation wheel wheelLayer = CALayer() wheelLayer.frame = CGRect(x: 20, y: 20, width: self.frame.width-40, height: self.frame.height-40) diff --git a/Source/SelectedColorView.swift b/Source/SelectedColorView.swift index 9ba1bda..53c2aef 100755 --- a/Source/SelectedColorView.swift +++ b/Source/SelectedColorView.swift @@ -10,6 +10,29 @@ import UIKit class SelectedColorView: UIView { var color: UIColor! + // Describe color for VoiceOver users + override var accessibilityLabel: String? { + set { } + get { + var red: CGFloat = 0.0, green: CGFloat = 0.0, blue: CGFloat = 0.0 + self.color.getRed(&red, green: &green, blue: &blue, alpha: nil) + + let colorString = NSLocalizedString("Color", comment: "Title for color") + let redString = NSLocalizedString("Red", comment: "The color red") + let greenString = NSLocalizedString("Green", comment: "The color green") + let blueString = NSLocalizedString("Blue", comment: "The color blue") + + let percentFormatter = NumberFormatter() + percentFormatter.numberStyle = .percent + + let redPercent = percentFormatter.string(from: NSNumber(floatLiteral: Double(red)))! + let greenPercent = percentFormatter.string(from: NSNumber(floatLiteral: Double(green)))! + let bluePercent = percentFormatter.string(from: NSNumber(floatLiteral: Double(blue)))! + + return "\(colorString), \(redPercent) \(redString), \(greenPercent) \(greenString), \(bluePercent) \(blueString)" + } + } + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } @@ -18,6 +41,9 @@ class SelectedColorView: UIView { super.init(frame: frame) setViewColor(color) + + // Make accessible + self.isAccessibilityElement = true } func setViewColor(_ _color: UIColor) {