Skip to content

Instantly share code, notes, and snippets.

View dadederk's full-sized avatar
💻

Daniel Devesa dadederk

💻
View GitHub Profile
@dadederk
dadederk / AccessibilitySpeechLanguage.swift
Created May 25, 2022 11:52
Announce something in a different language than the default one being used with VoiceOver using an accessibility attributed label with the accessibilitySpeechLanguage attribute. #365DaysIOSAccessibility. Day 7.
let greetingLessonView = UIView()
let bcp47LanguageCode = "es-Es"
let translatedPhrase = "¡Buenos días! "
let attributedLabel = NSMutableAttributedString(string: translatedPhrase,attributes: [.accessibilitySpeechLanguage: bcp47LanguageCode])
attributedLabel.append(NSAttributedString(string: "Means: good morning!"))
greetingLessonView.accessibilityAttributedLabel = attributedLabel
@dadederk
dadederk / AccessibilitySpeechIPANotation.swift
Last active May 31, 2022 09:57
Correct VoiceOver's pronunciation using an accessibility attributed label and the accessibilitySpeechIPANotation attribute. #365DaysIOSAccessibility. Day 9.
let liveNewsChannelView = UIView()
let attributedLabel = NSMutableAttributedString(string: "24 hour news channel. ")
attributedLabel.append(NSAttributedString(string: "Live",attributes: [.accessibilitySpeechIPANotation: "laɪv"]))
liveNewsChannelView.accessibilityAttributedLabel = attributedLabel
@dadederk
dadederk / SelectedTrait.swift
Created January 13, 2021 21:22
Insert or remove selected accessibility trait.
if likeButton.isSelected {
accessibilityTraits.insert(.selected)
} else {
accessibilityTraits.remove(.selected)
}
@dadederk
dadederk / CustomActions.swift
Created May 13, 2020 08:41
Configure Custom Actions with handlers.
// Create Custom Actions
let artistCustomAction = UIAccessibilityCustomAction(name: userName) { _ in
self.navigationController?.present(artistViewController, animated: true, completion: nil)
return true
}
let likeCustomAction = UIAccessibilityCustomAction(name: "like") { _ in
likedSongs.append(song)
return true
}
@dadederk
dadederk / AutoplayEnabled.swift
Created May 13, 2020 08:38
How to check if the user has disabled autoplay for previews.
// Check if the user has Video Autoplay enabled
if UIAccessibility.isVideoAutoplayEnabled {
video.play()
} else {
video.pause()
}
@dadederk
dadederk / DifferentiateWithoutColor.swift
Created May 13, 2020 08:30
Deal with the Differentiate Without Color configuration.
// Check if the user needs differentiation without color
if UIAccessibility.shouldDifferentiateWithoutColor {
card.colorSymbolImageView.hidden = false
} else {
card.colorSymbolImageView.hidden = true
}
@dadederk
dadederk / LargeContentViewer.swift
Created May 13, 2020 08:28
Supporting Large Content Viewer in your custom views.
// Create a Large Content Viewer Interaction
let largeContentViewerInteraction = UILargeContentViewerInteraction()
// Add it to your view
customBarView.addInteraction(largeContentViewerInteraction)
// Enable Large Content Viewer in the buttons or labels you want
customBarTabButton.showsLargeContentViewer = true
// If it is a custom view that you want to enable for Large Content Viewer,
@dadederk
dadederk / VoiceControl.swift
Last active May 13, 2020 08:43
Adding alternative user input accessibility labels for Voice Control
// Provide input alternatives for Voice Control
settingsButton.accessibilityUserInputLabels = ["settings", "configuration", "cog"]