如何更改 VoiceOver 对没有标题(仅图像)的 NSButton 读取的内容?

发布于 2024-12-20 11:11:22 字数 441 浏览 3 评论 0原文

我有一些仅是图像的 NSButton,并且完全以编程方式设置。当 VoiceOver 读取这些按钮时,它会为每个按钮显示“未选中的复选框”。我想为 VoiceOver 设置一个更具描述性的属性来读取(出于可访问性目的),但我无法在按钮上设置标题属性,因为随后将显示标题(我只想显示图标)。

我尝试使用

[self.button accessibilitySetOverrideValue:title forAttribute:NSAccessibilityDescriptionAttribute];

但没有任何改变。我还尝试了 NSAccessibilityTitleAttribute、NSAccessibilityRoleDescriptionAttribute 和 NSAccessibilityRoleAttribute,但没有成功。我做错了什么吗?

谢谢。

I have a few NSButtons that are images only, and are set completely programmatically. When VoiceOver reads these buttons, it says "unchecked checkbox" for each of them. I'd like to set an attribute for VoiceOver to read that is more descriptive (for accessibility purposes), but I can't set the title attribute on the button because the title will then be displayed (I only want the icon to be displayed).

I tried using

[self.button accessibilitySetOverrideValue:title forAttribute:NSAccessibilityDescriptionAttribute];

but nothing changed. I also tried NSAccessibilityTitleAttribute, NSAccessibilityRoleDescriptionAttribute, and NSAccessibilityRoleAttribute with no luck. Am I doing something incorrectly?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔岸观火 2024-12-27 11:11:22

看起来原始代码是正确的,但它仅在按钮单元(而不是按钮本身)上调用时才有效。上面的内容更改为:

[self.button.cell accessibilitySetOverrideValue:title forAttribute:NSAccessibilityDescriptionAttribute];

其中 title 仍然是 NSString*。假设标题为 @"Test",上述代码会导致 VoiceOver 读取“测试未选中的复选框”。我发现让它不读取“未选中的复选框”部分的唯一方法是清除其他三个属性:NSAccessibilityTitleAttributeNSAccessibilityRoleDescriptionAttributeNSAccessibilityRoleAttribute 。我用 @" " 覆盖了每一个。如果有人有更优雅的解决方案来忽略这些字段,请告诉我。现在,我将标记此答案。

It looks like the original code was correct, but it only works when called on the button cell (not the button itself). The above was changed to:

[self.button.cell accessibilitySetOverrideValue:title forAttribute:NSAccessibilityDescriptionAttribute];

where title is still an NSString*. Assuming title is @"Test", the above code causes VoiceOver to read "Test unchecked checkbox." The only way I found to have it not read the "unchecked checkbox" parts was to clear three other attributes: NSAccessibilityTitleAttribute, NSAccessibilityRoleDescriptionAttribute, and NSAccessibilityRoleAttribute. I overrode each of these with @" ". If anyone has a more elegant solution to ignore these fields, please let me know. For now, I'll mark this answered.

樱桃奶球 2024-12-27 11:11:22

在 Yosemite (10.10) 中,您可以使用 方法-基于辅助功能 API 来执行此操作:

例如,在自定义 NSView 中:

class CustomTabBarGroup: NSView, NSAccessibilityGroup {

    required init?(coder: NSCoder) {
        super.init(coder: coder)

        // We function as a tab group — closest in role is a radio button group
        self.setAccessibilityRole(NSAccessibilityRadioGroupRole)

        // You can also override what the role normally reads:
        self.setAccessibilityRoleDescription("Tab bar")
    }

    //...
}

并且,可能在行为类似于应用程序中的单选按钮的开关按钮上(例如,像从多个选项卡中选择一个):

class CustomTabBarButton: NSButton {

    required init?(coder: NSCoder) {
        super.init(coder:coder)
        self.setAccessibilityRole(NSAccessibilityRadioButtonRole)
    }

    //...
}

有关采用此类角色的非标准外观控件的示例,请查看 iPhoto 的“调整”面板。带有“快速修复”、“效果”和“调整”选项卡的右侧选项卡栏实际上是一个带有单选按钮的单选按钮组。此外,“效果”选项卡下的效果样本还包括步进器、复选框和按钮。

In Yosemite (10.10), you can use the method-based accessibility API to do this:

e.g., in a Custom NSView:

class CustomTabBarGroup: NSView, NSAccessibilityGroup {

    required init?(coder: NSCoder) {
        super.init(coder: coder)

        // We function as a tab group — closest in role is a radio button group
        self.setAccessibilityRole(NSAccessibilityRadioGroupRole)

        // You can also override what the role normally reads:
        self.setAccessibilityRoleDescription("Tab bar")
    }

    //...
}

And, maybe on a switch button that behaves like a radio button in your app (e.g., like a selected tab out of several):

class CustomTabBarButton: NSButton {

    required init?(coder: NSCoder) {
        super.init(coder:coder)
        self.setAccessibilityRole(NSAccessibilityRadioButtonRole)
    }

    //...
}

For an example of controls with non-standard appearance adopting such roles, check out iPhoto’s Adjust panel. The right-hand tab bar with the "Quick fixes", "Effects", and "Adjust" tabs is actually a radio button group with radio buttons. Also the effect swatches under the Effects tab are steppers, checkboxes, and a button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文