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

后端 未结 5 1633
孤街浪徒
孤街浪徒 2020-12-09 08:31

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?

相关标签:
5条回答
  • 2020-12-09 08:59

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

    You could simply access it as view.accessibilityIdentifier

    0 讨论(0)
  • 2020-12-09 09:01

    According to this page

    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.

    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.

    0 讨论(0)
  • 2020-12-09 09:04

    accessibilityIdentifier Only applicable for IOS 5.0 or Later....please Refer....

    https://developer.apple.com/library/ios/documentation/uikit/reference/UIAccessibilityIdentification_Protocol/Introduction/Introduction.html

    0 讨论(0)
  • 2020-12-09 09:12

    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?

    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.

    0 讨论(0)
  • 2020-12-09 09:17

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

    Key Path: accessibilityIdentifier

    Type: String

    Value: Chosen accessibilityIdentifier text

    E.g. setting a scroll view to have the accessibility 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.

    0 讨论(0)
提交回复
热议问题