如何更改 VoiceOver 对没有标题(仅图像)的 NSButton 读取的内容?
我有一些仅是图像的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来原始代码是正确的,但它仅在按钮单元(而不是按钮本身)上调用时才有效。上面的内容更改为:
其中 title 仍然是
NSString*
。假设标题为@"Test"
,上述代码会导致 VoiceOver 读取“测试未选中的复选框”。我发现让它不读取“未选中的复选框”部分的唯一方法是清除其他三个属性:NSAccessibilityTitleAttribute
、NSAccessibilityRoleDescriptionAttribute
和NSAccessibilityRoleAttribute
。我用@" "
覆盖了每一个。如果有人有更优雅的解决方案来忽略这些字段,请告诉我。现在,我将标记此答案。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:
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
, andNSAccessibilityRoleAttribute
. 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.在 Yosemite (10.10) 中,您可以使用 方法-基于辅助功能 API 来执行此操作:
例如,在自定义 NSView 中:
并且,可能在行为类似于应用程序中的单选按钮的开关按钮上(例如,像从多个选项卡中选择一个):
有关采用此类角色的非标准外观控件的示例,请查看 iPhoto 的“调整”面板。带有“快速修复”、“效果”和“调整”选项卡的右侧选项卡栏实际上是一个带有单选按钮的单选按钮组。此外,“效果”选项卡下的效果样本还包括步进器、复选框和按钮。
In Yosemite (10.10), you can use the method-based accessibility API to do this:
e.g., in a Custom NSView:
And, maybe on a switch button that behaves like a radio button in your app (e.g., like a selected tab out of several):
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.