This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import Accessibility | |
| import UIKit | |
| class MyChartView: UIView, AXChart { | |
| var accessibilityChartDescriptor: AXChartDescriptor? { | |
| get { | |
| let xAxis = AXNumericDataAxisDescriptor(title: "Lines of code", range: 0...10, gridlinePositions: [2.5, 5.0, 7.5]) { number in | |
| "\(number) lines" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct ContentView: View { | |
| @Namespace var namespace | |
| @State private var isOn = false | |
| var body: some View { | |
| HStack { | |
| Text("I agree on the terms and conditions") | |
| .accessibilityLabeledPair(role: .label, id: "aPair", in: namespace) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let magnifyingGlassIcon = UIImage(systemName: "magnifyingglass")! | |
| let searchButton = UIButton() | |
| let searchTutorialLabel = UILabel() | |
| searchButton.accessibilityLabel = "search" | |
| let textAttachment = NSTextAttachment(image: magnifyingGlassIcon) | |
| let string = "Select the <icon> button to find elements in the list" | |
| let attributedString = NSMutableAttributedString(string: string) | |
| let attributedStringIcon = NSAttributedString(attachment: textAttachment) | |
| let iconPlaceholderRange = attributedString.string.range(of: "<icon>")! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override var accessibilityValue: String? { | |
| get { | |
| let formatter = MeasurementFormatter() | |
| let measurement = Measurement<UnitLength>( | |
| value: Double(value), | |
| unit: .kilometers | |
| ) | |
| formatter.unitStyle = .long | |
| return formatter.string(from: measurement) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func accessibilityIncrement() { | |
| guard value < 5 else { return } | |
| value += 1 | |
| accessibilityValue = "\(value) of 5" | |
| sendActions(for: .valueChanged) | |
| } | |
| override func accessibilityDecrement() { | |
| guard value > 1 else { return } | |
| value -= 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let dailyAverageLabel = UILabel() | |
| let abbreviatedReadableFormatter = DateComponentsFormatter() | |
| abbreviatedReadableFormatter.allowedUnits = [.hour, .minute] | |
| abbreviatedReadableFormatter.unitsStyle = .spellOut | |
| let abbreviatedReadableDuration = abbreviatedReadableFormatter.string(from: 12240) | |
| dailyAverageLabel.accessibilityLabel = abbreviatedReadableDuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let codeLabel = UILabel() | |
| let attributedLabel = NSAttributedString( | |
| string: "BAC1234567D", | |
| attributes: [.accessibilitySpeechSpellOut: true] | |
| ) | |
| title.accessibilityAttributedLabel = attributedLabel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let codeLabel = UILabel() | |
| let attributedLabel = NSAttributedString( | |
| string: "let myString: String = \"Hello world\"", | |
| attributes: [.accessibilitySpeechPunctuation: true] | |
| ) | |
| codeLabel.accessibilityAttributedLabel = attributedLabel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let tweetView = UIView() | |
| let userName = "Daniel Devesa Derksen-Staats" | |
| let userHandle = "@dadederk" | |
| let timestamp = "" | |
| let text = "Tweeting about developing accessible #iOS apps in #365daysIOSAccessibility #accessibility #a11y" // 80, 92, 115 | |
| // Returns pairs of hashtag strings and the range in the tweet | |
| func hashtags(_ string: String) -> [(String, NSRange)] {...} | |
| let tweetLabel = [userName, userHandle, timestamp, text].joined(separator: ". ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let recipeNameLabel = UILabel() | |
| let attributedLabel = NSAttributedString( | |
| string: "Paella", | |
| attributes: [.accessibilitySpeechIPANotation: "pɑːˈeɪə"] | |
| ) | |
| recipeNameLabel.accessibilityAttributedLabel = attributedLabel |
NewerOlder