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
can I set accessibility identifier in interface builder? Xcode4.2
提问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
回答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':
例如,将滚动视图设置为具有可访问性 ID 'ScrollView':
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
根据这个页面
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 user3131492
accessibilityIdentifier Only applicable for IOS 5.0 or Later....please Refer....
accessibilityIdentifier 仅适用于 IOS 5.0 或更高版本....请参考....
回答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。