diff --git a/.gitignore b/.gitignore
index ad7cc753..6083f140 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,9 @@ DerivedData
*.hmap
*.ipa
+# AppCode
+.idea
+
# Bundler
.bundle
vendor
diff --git a/Example-iOS/DemoStrings.swift b/Example-iOS/DemoStrings.swift
index c021194f..33a422bc 100644
--- a/Example-iOS/DemoStrings.swift
+++ b/Example-iOS/DemoStrings.swift
@@ -32,7 +32,10 @@ enum DemoStrings {
let localizedString = "I want to be different. If everyone is wearing black, I want to be wearing red.\nMaria Sharapova "
// Define a colored image that's slightly shifted to account for the line height
- let racket = UIImage(named: "Tennis Racket")!.styled(with:
+ let accessibleRacketImage = UIImage(named: "Tennis Racket")!
+ // The racket is purely for decoration, so make the accessibility system ignore it
+ accessibleRacketImage.accessibilityLabel = ""
+ let racket = accessibleRacketImage.styled(with:
.color(.raizlabsRed), .baselineOffset(-4.0))
// Define styles
@@ -65,7 +68,9 @@ enum DemoStrings {
/// composition only if you absolutely need to build the string from pieces.
static let compositionExample: NSAttributedString = {
// Define a colored image that's slightly shifted to account for the line height
- let boat = UIImage(named: "boat")!.styled(with:
+ let accessibleBoatImage = UIImage(named: "boat")!
+ accessibleBoatImage.accessibilityLabel = "boat"
+ let boat = accessibleBoatImage.styled(with:
.color(.raizlabsRed))
let baseStyle = StringStyle(
@@ -90,17 +95,30 @@ enum DemoStrings {
], baseStyle: baseStyle)
}()
- static let imagesExample = NSAttributedString.composed(of: [
- "2".styled(with: .baselineOffset(8)),
- UIImage(named: "bee")!,
- UIImage(named: "oar")!,
- UIImage(named: "knot")!,
- "2".styled(with: .baselineOffset(8)),
- UIImage(named: "bee")!,
+ static let imagesExample: NSAttributedString = {
+
+ func accessibleImage(named name: String) -> UIImage {
+ let image = UIImage(named: name)!
+ image.accessibilityLabel = name
+ return image
+ }
+
+ let bee = accessibleImage(named: "bee")
+ let oar = accessibleImage(named: "oar")
+ let knot = accessibleImage(named: "knot")
+
+ return NSAttributedString.composed(of: [
+ "2".styled(with: .baselineOffset(8)),
+ bee,
+ oar,
+ knot,
+ "2".styled(with: .baselineOffset(8)),
+ bee,
], baseStyle: StringStyle(
.font(UIFont(name: "HelveticaNeue-Bold", size: 24)!),
.adapt(.control)
))
+ }()
static let noBreakSpaceExample: NSAttributedString = {
let noSpaceTextStyle = StringStyle(
diff --git a/Sources/Image+Tinting.swift b/Sources/Image+Tinting.swift
index 03f739cf..8069f2f1 100644
--- a/Sources/Image+Tinting.swift
+++ b/Sources/Image+Tinting.swift
@@ -64,6 +64,9 @@ public extension BONImage {
// Prevent further tinting
image.isTemplate = false
+ // Transfer accessibility description
+ image.accessibilityDescription = self.accessibilityDescription
+
return image
}
#else
@@ -113,6 +116,11 @@ public extension BONImage {
image = image.resizableImage(withCapInsets: originalCapInsets, resizingMode: originalResizingMode)
}
+ // Transfer accessibility label (watchOS not included; does not have accessibilityLabel on UIImage).
+ #if os(iOS) || os(tvOS)
+ image.accessibilityLabel = self.accessibilityLabel
+ #endif
+
return image
}
#endif
diff --git a/Tests/ImageTintingTests.swift b/Tests/ImageTintingTests.swift
index 1a64fe33..c6791501 100644
--- a/Tests/ImageTintingTests.swift
+++ b/Tests/ImageTintingTests.swift
@@ -25,6 +25,8 @@ class ImageTintingTests: XCTestCase {
let raizlabsRed = UIColor(red: 0.92549, green: 0.352941, blue: 0.301961, alpha: 1.0)
#endif
+ let accessibilityDescription = "I’m the very model of a modern accessible image."
+
func testImageTinting() {
let blackImageName = "rz-logo-black"
let redImageName = "rz-logo-red"
@@ -85,4 +87,21 @@ class ImageTintingTests: XCTestCase {
BONAssertEqualImages(untintedResult!, tintAttemptResult!)
}
+ func testAccessibilityIOSAndTVOS() {
+ #if os(iOS) || os(tvOS)
+ imageForTest.accessibilityLabel = accessibilityDescription
+ let tintedImage = imageForTest.tintedImage(color: raizlabsRed)
+ XCTAssertEqual(tintedImage.accessibilityLabel, accessibilityDescription)
+ XCTAssertEqual(tintedImage.accessibilityLabel, tintedImage.accessibilityLabel)
+ #endif
+ }
+
+ func testAccessibilityOSX() {
+ #if os(OSX)
+ imageForTest.accessibilityDescription = accessibilityDescription
+ let tintedImage = imageForTest.tintedImage(color: raizlabsRed)
+ XCTAssertEqual(tintedImage.accessibilityDescription, accessibilityDescription)
+ XCTAssertEqual(tintedImage.accessibilityDescription, tintedImage.accessibilityDescription)
+ #endif
+ }
}