Skip to content

Instantly share code, notes, and snippets.

@SeanMcTex
Created June 4, 2014 15:40
Show Gist options
  • Save SeanMcTex/82cf8e10eaba3b03ac46 to your computer and use it in GitHub Desktop.
Save SeanMcTex/82cf8e10eaba3b03ac46 to your computer and use it in GitHub Desktop.
Quick Reference for the Most Commonly Needed Accessibility Functionality in Swift for iOS

Accessibility Cheat Sheet for Swift

The Basics

fireButton.accessibilityLabel = NSLocalizedString( "Fire Weapons", comment: "Fire weapons button label" )
fireButton.isAccessibilityElement = true
fireButton.accessibilityHint = "Clearly, you should push this button to shoot your weapons at the bad guys"

Notifications

UIAccessibilityPostNotification( UIAccessibilityScreenChangedNotification, self.fireButton )
UIAccessibilityPostNotification( UIAccessibilityLayoutChangedNotification, nil )

Additional Methods

override func accessibilityDecrement()  {
	self.value -= 0.01;
}

override func accessibilityIncrement()  {
	self.value += 0.01;
}

override func accessibilityActivate() -> Bool {
	self.value = ( self.value == 0.0 ) ? 1.0 : 0.0;
	return true
}

Responding to Accessibility Settings

if ( UIAccessibilityIsGrayscaleEnabled() ) {
    self.tintColor = UIColor.blackColor()
}

if ( UIAccessibilityIsReduceTransparencyEnabled() ) {
    self.alpha = 1.0
} else {
    self.alpha = 0.8
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment