Question:
How do I add a custom VoiceOver accessibility
Label
orHint
to an App
Icon Badge Number?
例如,当iOS设置辅助功能> VoiceOver已开启,VoiceOver朗读在屏幕上触摸的项目.对于App Store和Mail图标,大声朗读以下内容:
App Store icon,VoiceOver says: “App Store. 2 updates available.
Double tap to open.”Mail icon,VoiceOver says: “Mail. 1 unread message. Double tap
to open.”
但是,对于我正在开展的项目,VoiceOver读出是通用的,并不完全有用:
My App icon,VoiceOver says: “My App. 123 new items. Double tap to
open.”
短语“…新项目”太模糊,不准确,我确定必须有一种方法可以使用自定义字符串进行更改,以便通过设置accessibilityLabel,accessibilityHint或类似的东西来更好地阅读.
但是Swift代码究竟如何呢?
非常感谢.
附加观察:
使用模拟器辅助功能检查器,VoiceOver值会显示在标签 – “我的应用程序”和值 – “123个新项目”中.所以在代码中更新,我已经尝试将accessibilityValue设置为自定义 – “123自定义描述”.但仍然没有运气,VoiceOver继续阅读“我的应用程序123新项目,双击打开”.
为什么VoiceOver不按预期方式阅读自定义徽章值?
码:
以下方法在我的应用程序图标上添加了一个红色圆圈应用程序图标徽章号码:
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let badgeCount: Int = 123 let application = UIApplication.sharedApplication() if #available(iOS 8.0,*) { //// iOS 8,iOS 9,iOS 10 application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Badge],categories: nil)) } else { //// iOS 7 } application.applicationIconBadgeNumber = badgeCount application.accessibilityValue = "123 custom description." } }