ios 我可以在界面生成器中设置辅助功能标识符吗?Xcode4.2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7901100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:03:39  来源:igfitidea点击:

can I set accessibility identifier in interface builder? Xcode4.2

iosaccessibilityios-ui-automation

提问by CarmeloS

I can only set Accessibility Label in interface builder, but in UI Automation,I need Accessibility Identifier to get the UI elements. any way to do this?

我只能在界面构建器中设置辅助功能标签,但在 UI 自动化中,我需要辅助功能标识符来获取 UI 元素。有什么办法可以做到这一点?

采纳答案by Anees

In Xcode 7.1 (ios 9.0) you could do it as simple as possible. Please find the image attached.

在 Xcode 7.1 (ios 9.0) 中,您可以尽可能简单地做到这一点。请找到所附的图片。

enter image description here

在此处输入图片说明

You could simply access it as view.accessibilityIdentifier

您可以简单地将其作为 view.accessibilityIdentifier 访问

回答by Joseph

The accessibilityIndentifier can be set in IB by using the Identity Inspector tab's 'User Defined Runtime Attributes':

可以使用 Identity Inspector 选项卡的“用户定义的运行时属性”在 IB 中设置 accessibilityIndentifier:

Key Path: accessibilityIdentifier

关键路径:accessibilityIdentifier

Type: String

类型:字符串

Value: Chosen accessibilityIdentifier text

值:选择的可访问性标识符文本

E.g. setting a scroll view to have the accessibility ID 'ScrollView': Image from Xcode 8.3.2

例如,将滚动视图设置为具有可访问性 ID 'ScrollView': 来自 Xcode 8.3.2 的图片

Note: This can only be used on items that have the accessibilityIdentifier property meaning they inherit from UIView. Also, typos in 'Key Path' will probably cause an exception when the item is loaded, I don't believe a compile warning/error would be given.

注意:这只能用于具有 accessibilityIdentifier 属性的项目,这意味着它们从 UIView 继承。此外,“关键路径”中的拼写错误可能会在加载项目时导致异常,我认为不会给出编译警告/错误。

回答by Nick Lockwood

According to this page

根据这个页面

http://developer.apple.com/library/ios/#documentation/AnalysisTools/Conceptual/WhatsNewInstruments/NewFeatures42/NewFeatures42.html

http://developer.apple.com/library/ios/#documentation/AnalysisTools/Conceptual/WhatsNewInstruments/NewFeatures42/NewFeatures42.html

UIAutomation will use the accessibilityLabel if the accessibilityIdentifier is not set, so you can use that instead for now. This probably isn't best practice though because the accessibilityLabel is visible (or rather audible) to the user if they are using VoiceOver, but it's okay as long as you give the labels names that are meaningful to humans.

如果未设置 accessibilityIdentifier ,UIAutomation 将使用 accessibilityLabel ,因此您现在可以使用它。但这可能不是最佳实践,因为如果用户使用 VoiceOver,accessibilityLabel对用户是可见的(或者更确切地说是可听的),但是只要您提供对人类有意义的标签名称就可以了。

Hopefully Apple will add a way to set the accessibilityIdentifier in IB in future, but for now you'll have to set it in code, or use something else such as the view tag to target views for automation.

希望 Apple 将来会添加一种在 IB 中设置 accessibilityIdentifier 的方法,但现在您必须在代码中设置它,或者使用其他内容(例如视图标记)来定位视图以实现自动化。

回答by SimpleApp

I was wondering, do you want to test things from xib that don't have IBOutlet? Can someone with more experience share his/hers thoughts?

我想知道,你想从没有 IBOutlet 的 xib 测试东西吗?有更多经验的人可以分享他/她的想法吗?

Here is my view on the subject. If you don't assign IBOutlet to a button/label/texBox or what ever this means you won't change it from the code. The control will be static and you can see it in Interface builder. If you add an IBOutlet to a control then you can add acessibilityIdentifier from the code.

这是我对这个问题的看法。如果您不将 IBOutlet 分配给按钮/标签/texBox 或其他任何意味着您不会从代码中更改它。该控件将是静态的,您可以在界面构建器中看到它。如果将 IBOutlet 添加到控件,则可以从代码中添加 acessibilityIdentifier。