A11yKit is a powerful and easy-to-use Swift library for automating accessibility improvements in iOS applications. It helps developers create more inclusive apps by automatically optimizing UI elements for VoiceOver, Dynamic Type, and color contrast.
- Automatic optimization for VoiceOver accessibility
- Dynamic Type support for better text readability
- Color contrast enhancement for improved visibility
- Customizable optimization options
- Accessibility auditing and report generation
- Logging system for tracking optimizations
- Undo functionality for optimization actions
- Asynchronous optimization support
- Intelligent filtering of UI elements for optimization
A11yKit helps your app comply with the following accessibility standards:
- WCAG 2.1 (Web Content Accessibility Guidelines)
- Supports up to AAA level for color contrast
- iOS Accessibility Best Practices
- Section 508 of the Rehabilitation Act
- iOS 13.0+
- Swift 5.3+
- Xcode 12.0+
You can install A11yKit using the Swift Package Manager. Add the following to your
Package.swift file:
dependencies: [
.package(url: "https://github.com/DAWNCR0W/A11yKit.git", from: "0.1.2")
]import A11yKit
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Optimize all views in the view controller
A11yKit.shared.optimizeAll(self)
}
}import A11yKit
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let a11y = A11yKit.shared
// Configure A11yKit
a11y.setLoggingEnabled(true)
var config = A11yConfiguration()
config.minimumContrastRatio = 7.0 // WCAG AAA standard
config.preferredContentSizeCategory = .large
config.enableVoiceOverOptimization = true
config.enableDynamicType = true
config.enableColorContrastOptimization = true
config.autoGenerateVoiceOverLabels = true
a11y.updateConfiguration(config)
// Optimize with specific options
a11y.optimizeAll(self, options: [.voiceOver, .dynamicType, .colorContrast])
// Optimize a specific view
if let specialView = view.viewWithTag(100) {
a11y.optimize(specialView, options: .colorContrast)
}
// Generate an accessibility report
let report = a11y.generateAccessibilityReport(for: self)
print(report)
// Perform an accessibility audit
let issues = a11y.auditAll(self)
print("Found \(issues.count) accessibility issues")
// Undo last optimization
a11y.undoLastOptimization()
// Get diagnostic information
let diagnosticInfo = a11y.getDiagnosticInfo()
print(diagnosticInfo)
// Exclude specific views or view classes from optimization
a11y.excludeViewFromOptimization(someInternalView)
a11y.excludeViewClassFromOptimization(UIVisualEffectView.self)
// Add custom class prefix to auto-exclude list
a11y.addAutoExcludedClassPrefix("MyApp_Internal")
}
func optimizeAsync() async {
await A11yKit.shared.optimizeAsync(view)
}
}A11yKit provides several customization options through A11yConfiguration:
isEnabled: Enable or disable A11yKitlogLevel: Set the logging levelautoGenerateVoiceOverLabels: Automatically generate VoiceOver labelsenableDynamicType: Enable or disable Dynamic Type optimizationsenableColorContrastOptimization: Enable or disable color contrast optimizationsminimumContrastRatio: Set the minimum contrast ratio for color optimizationspreferredContrastRatio: Set the preferred contrast ratio for color optimizationsexcludedViewTags: Set of view tags to exclude from optimizationexcludedViewClasses: Set of view classes to exclude from optimizationminimumViewSize: Minimum size for views to be considered for optimizationautoExcludedClassPrefixes: Set of class name prefixes to automatically exclude from optimization
The main class that provides accessibility optimization methods.
optimize(_:options:): Optimize a single view with specified optionsoptimizeAll(_:options:): Optimize all views in a view controlleroptimizeVoiceOver(for:): Optimize a view for VoiceOveroptimizeDynamicType(for:): Optimize a view for Dynamic TypeoptimizeColorContrast(for:): Optimize a view's color contrastresetAccessibilityProperties(for:): Reset accessibility properties for a viewgenerateAccessibilityReport(for:): Generate an accessibility report for a view controllerperformAccessibilityAudit(on:): Perform an accessibility audit on a view controllerupdateConfiguration(_:): Update the A11yKit configurationsetLoggingEnabled(_:): Enable or disable loggingsetMinimumContrastRatio(_:): Set the minimum contrast ratiosetPreferredContentSizeCategory(_:): Set the preferred content size categoryundoLastOptimization(): Undo the last optimization actionoptimizeAsync(_:options:): Asynchronously optimize a viewexcludeViewFromOptimization(_:): Exclude a specific view from optimizationexcludeViewClassFromOptimization(_:): Exclude a specific view class from optimizationaddAutoExcludedClassPrefix(_:): Add a class name prefix to the auto-exclude listremoveAutoExcludedClassPrefix(_:): Remove a class name prefix from the auto-exclude list
An option set that specifies which optimizations to apply.
.voiceOver: Optimize for VoiceOver.dynamicType: Optimize for Dynamic Type.colorContrast: Optimize color contrast.all: Apply all optimizations
Contributions to A11yKit are welcome! Please feel free to submit a Pull Request.
A11yKit is released under the MIT license. See LICENSE for more information.