Created
April 14, 2021 05:32
-
-
Save yosshi4486/88599ef94c3eac9f425902abcbb67c37 to your computer and use it in GitHub Desktop.
日付表示のアクセシビリティ
This file contains 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
private func accessibilityLabelForCreatedDateLabel(from date: Date) -> String { | |
return String(format: NSLocalizedString("Created: %@", comment: "An accessibility label of created date."), self.accessibilityLabel(for: date) ?? "") | |
} | |
private func accessibilityLabelForUpdatedDateLabel(from date: Date) -> String { | |
return String(format: NSLocalizedString("Updated: %@", comment: "An accessibility label of updated date."), self.accessibilityLabel(for: date) ?? "") | |
} | |
private func accessibilityLabel(for date: Date) -> String? { | |
let timeComponentFormatter = DateComponentsFormatter() | |
timeComponentFormatter.unitsStyle = .spellOut // spellOutを利用するのが重要な点 | |
let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: date) | |
return timeComponentFormatter.string(from: components) | |
} | |
// https://developer.apple.com/documentation/foundation/datecomponentsformatter/unitsstyle | |
// spellOutは発生用に用意されているフォーマットで、時間をちゃんと読み上げてくれる。 | |
// これが正しい対応かどうかはわからない。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment