我正在向我的 SwiftUI 应用程序中添加可访问性,直到在 a中添加accessibilityLabel(_:)
a时遇到问题。这是一些示例代码:Button
ToolbarItem
struct ContentView: View {
var body: some View {
NavigationView {
Text("Content")
.accessibilityElement()
.accessibilityLabel("Content label") // This is here just to show Voice Control is working
.navigationTitle("Test")
.toolbar {
// Comment parts out below, depending on what you want to test
ToolbarItem(placement: .navigationBarTrailing) {
// What I want, but doesn't work:
// (Also tried adding the label to either the button
// label or the whole button itself, neither works.)
Button {
print("Pressed")
} label: {
Image(systemName: "plus")
.accessibilityElement()
.accessibilityLabel("Some label")
}
.accessibilityElement()
.accessibilityLabel("Some other label")
// What I don't want, but does work:
Image(systemName: "plus")
.accessibilityLabel("Another label")
}
}
}
}
}
我正在使用Voice Control测试可访问性。奇怪的是,可访问性标签适用于工具栏项目中的图像,但不适用于工具栏项目中的按钮内。
当我说可访问性标签不起作用时,它会说"Add"
而不是预期的标签。我假设 SwiftUI 默认为系统映像“加号”创建此标签,但我想更改它。
当不在工具栏项目中时,按钮可访问性标签也可以工作。这是一个错误,还是我造成的一些问题?