我有以下代码。
let text = "as of 07/29/2020"
textLabel.text = text语音重读-“截至07斜杠29斜杠2千人和20”
我怎样才能发音像“七月二十九二千”呢?
发布于 2020-07-13 15:57:08
回答不确定你到底想要解决什么。但希望这能帮上忙。
步骤1:您需要使用可访问性标签属性label.accessibilityLabel = "some string"
第二步:把你的约会对象转换成一个更友好的字符串,让你的声音结束。您可以通过使用Date()对象来做到这一点,并为标签和语音转换标签设置不同的格式。这是一个快速创建日期的链接。
下面是指向文档的链接,以及提到可访问性标签的部分。
游乐场示例:然后您的代码将类似于.
import UIKit
import PlaygroundSupport
let label = UILabel()
let dateForLabel = formatDate(date: Date(), style: .short)
let dateStringForLabel = "as of \(dateForLabel)"
label.text = dateStringForLabel
let dateForVoiceOverLabel = formatDate(date: Date(), style: .long)
let dateStringForVoiceOver = "as of \(dateForVoiceOverLabel)"
label.accessibilityLabel = dateStringForVoiceOver
func formatDate(date: Date, style: DateFormatter.Style) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = style
dateFormatter.timeStyle = .none
let date = date
// US English Locale (en_US)
dateFormatter.locale = Locale(identifier: "en_US")
return dateFormatter.string(from: date) // Jan 2, 2001
}创建Date()对象的链接 How do you create a Swift Date object?
链接到可访问性标签 https://developer.apple.com/documentation/uikit/accessibility_for_ios_and_tvos/supporting_voiceover_in_your_app上的苹果文档
“为VoiceOver无法访问的元素更新应用程序的可访问性,首先改进它们的可访问性标签和提示:
accessibilityLabel属性提供了VoiceOver在用户选择元素时读取的描述性文本。
accessibilityHint属性为所选元素提供附加上下文(或操作)。
可访问性标签非常重要,因为它们提供了VoiceOver读取的文本。一个好的可访问性标签应该是简短和信息丰富的。需要注意的是,UILabel和accessibilityLabel是不同的东西。默认情况下,VoiceOver读取与标准UIKit控件(如UILabel和UIButton )关联的文本。但是,这些控件也可以具有相应的accessibilityLabel属性,以添加有关标签或按钮的更多细节。
根据上下文,提示并不总是必要的。在某些情况下,标签提供了足够的上下文。如果您觉得自己在可访问性标签中说的太多了,请考虑将该文本移到提示中。
为了确保用户理解界面的意图,您可能需要手动设置一些辅助功能标签。可访问性标签和提示可以在Xcode的标识检查器中设置,也可以通过编程方式设置。“
https://stackoverflow.com/questions/62878615
复制相似问题