ios 在子线程访问属性
Attributed accessibility labels are an incredible tool for making some next-level accessible experiences. They let you tell VoiceOver not just what to speak, but how to say it too.
属性可访问性标签是一种令人难以置信的工具,可用于提供一些下级可访问体验。 他们使您不仅可以告诉VoiceOver说话的内容,还可以告诉他们如何说出来。
Using the accessibilityAttributedLabel property you can provide an NSAttributedString to VoiceOver, much the same way you would provide an NSAttributedString to a label’s attributedText property to display a string with an underline or character colour for example. The difference here is that all of our attributes are instructions for VoiceOver.
使用accessibilityAttributedLabel属性,你可以提供一个NSAttributedString到VoiceOver的,几乎相同的方式,你会提供一个NSAttributedString到标签的attributedText属性显示为下划线或字符颜色的字符串,例如。 此处的区别在于我们所有的属性都是VoiceOver的说明。
In the below example, we’re adding a pitch change to the word ‘best’ where in displayed text we might add a bold attribute to add emphasis. This means that your VoiceOver users will get a comparable experience to sighted users rather than a cut down one. This is the ultimate aim of digital accessibility. Create a comparable, inclusive interaction with your users, regardless of their abilities. Always ensure your text is localised and perform proper range calculations in your code, rather than hard coding everything as I am in this example.
在下面的示例中,我们为“最佳”一词添加了音高变化,其中在显示的文本中,我们可能会添加一个粗体属性以增加重点。 这意味着您的VoiceOver用户将获得与视觉用户可比的体验,而不是缩减的体验。 这是数字可访问性的最终目的。 不论用户的能力如何,都可以与他们进行可比的包容性互动。 始终确保您的文本是本地化的,并在代码中执行正确的范围计算,而不是像本例中那样对所有内容进行硬编码。
let attributedString = NSMutableAttributedString(string: "Thisis the best app on the App Store!")let range = attributedString.string.range(of: "best")attributedString.addAttributes([. accessibilitySpeechPitch: 1.5], range: range)appDescription?.accessibilityAttributedLabel = attributedStringMuch like visual NSAttributedStrings, there are several attributes to pick from to get the effect you’re aiming for.
与视觉NSAttributedString一样,有几种属性可供选择,以达到您想要的效果。
This attribute allows you to be explicit about the language VoiceOver uses to read a string. This is useful if you have multiple languages in your app. The attribute takes an argument representing the language you want VoiceOver to use in the BCP47 format such as this example for Latin American Spanish [.accessibilitySpeechLanguage: "es-419"].
此属性使您可以明确VoiceOver用来读取字符串的语言。 如果您的应用中有多种语言,这将很有用。 该属性接受一个参数,该参数表示您希望VoiceOver以BCP47格式使用的语言,例如拉丁美洲西班牙语[.accessibilitySpeechLanguage: "es-419"]示例。
Spelling out the text is the ideal solution to the reference number problem we discussed in the previous post. This attribute lets you keep a neat visual string of ‘1234’, but when marked with [.accessibilitySpeechSpellOut: true]this is read by VoiceOver as ‘1 2 3 4’.
拼写文本是我们在之前的文章中讨论的参考号问题的理想解决方案。 该属性使您可以保持整洁的可视字符串“ 1234”,但是当标记为[.accessibilitySpeechSpellOut: true] ,VoiceOver [.accessibilitySpeechSpellOut: true]其读取为“ 1 2 3 4”。
You can use phonetic Notation to give VoiceOver exact instructions about how it should pronounce a word. VoiceOver’s pronunciation is not always perfect, and while this is usually still understandable by your customer, there are instances where you might want to be more prescriptive. Your brand name is a great example of this, as VoiceOver may not read this exactly as your brand expects.
您可以使用注音符号为VoiceOver提供有关其应如何发音的确切说明。 VoiceOver的发音并不总是完美的,尽管客户通常仍然可以理解它,但是在某些情况下,您可能需要更多说明性的内容。 您的品牌名称就是一个很好的例子,因为VoiceOver可能不会完全按照您的品牌期望阅读。
Words you use commonly in your app that have a specific domain meaning are another great use. For example, VoiceOver can’t pronounce the word ‘expiry’ correctly. In the UK this word is used on credit cards as ‘expiration’ would be in the US. Meaning any app in the UK handling credit card data should probably use this technique to ensure customers understand what data they need to enter in a form.
您在应用中常用的具有特定域含义的词是另一种很好的用法。 例如,VoiceOver无法正确发音单词“ expiry”。 在英国,此单词在信用卡上使用,因为“过期”在美国会用到。 意味着英国的任何处理信用卡数据的应用都应使用此技术,以确保客户了解他们需要以表格形式输入哪些数据。
Homonyms are another good example. In the BBC Sounds app, users are offered the opportunity to listen to ‘live radio’. unfortunately, VoiceOver appears to be instructing the user to ‘liv radio’. This can be fixed using the .accessibilitySpeechIPANotation attribute and providing an IPA string, such as this example:
同名是另一个很好的例子。 在BBC Sounds应用程序中,为用户提供了收听“现场广播”的机会。 不幸的是,VoiceOver似乎正在指示用户“娱乐广播”。 可以使用.accessibilitySpeechIPANotation属性并提供IPA字符串来解决此问题,例如以下示例:
let attributedString = NSMutableAttributedString(string: "Live radio")let range = attributedString.string.range(of: "Live")attributedString.addAttributes([.accessibilitySpeechIPANotation: "līv"], range: range)liveRadio?.accessibilityAttributedLabel = attributedStringThis attribute allows us to tell VoiceOver to read all punctuation. This can be useful if your app features code or some other technical notation. Be sure to apply [.accessibilitySpeechPunctuation: true] only to the range that contains your code, otherwise listening to the result will take a while.
此属性使我们可以告诉VoiceOver读取所有标点符号。 如果您的应用程序具有代码或其他一些技术符号,则此功能很有用。 确保仅将[.accessibilitySpeechPunctuation: true]到包含您的代码的范围,否则监听结果将花费一些时间。
Daniel Devesa Developing Accessible iOS Apps: Support VoiceOver, Dynamic Type, and More
Daniel Devesa 开发可访问的iOS应用程序:支持VoiceOver,动态类型等
Rob Whitaker Developing Inclusive Mobile Apps: Building Accessible Apps for iOS and Android
Rob Whitaker 开发包容性移动应用程序:构建适用于iOS和Android的无障碍应用程序
This is the last article in the series of posts about iOS’ accessibility labels, so the next step is to go ahead and make some incredibly accessible apps!
这是有关iOS的辅助功能标签的系列文章中的最后一篇,因此下一步是继续制作一些令人难以置信的可访问应用程序!
The previous article in this series is Writing Great iOS Accessibility Labels.
本系列的上一篇文章是编写出色的iOS无障碍标签 。
iOS Accessibility Labels
iOS辅助功能标签
When to use Accessibility Labels
何时使用辅助功能标签
Writing Great iOS Accessibility Labels
编写出色的iOS无障碍标签
iOS Attributed Accessibility Labels
iOS属性可访问性标签
This post was originally published on mobilea11y.com. Visit Mobile A11y for more mobile accessibility tools and techniques.
该帖子最初发布在mobilea11y.com上 。 访问Mobile A11y,以获取更多的移动辅助工具和技术。
翻译自: https://medium.com/macoclock/ios-attributed-accessibility-labels-f54b8dcbf9fa
ios 在子线程访问属性