I'm hoping to use KIF to write functional tests for our iphone app. It uses "accessibility labels" to identify the UI items it's testing. How do I set the accessibility label for a view in xcode4's interface builder?
Asked
Active
Viewed 1.2k times
10
-
accessibilityLabel is read by VoiceOver. It is bad practice to use it as an identifier. You should use accessibilityIdentifer property which is not read by voiceover. – Vlad Jan 07 '17 at 00:03
-
@Vlad No. It's *best* practise to use it in functional tests, because then you're also testing that your app is accessible. – Simon Jan 07 '17 at 11:52
1 Answers
11
To set the variable programmatically you can use its property like this:
UIButton *someButton = [[UIButton alloc] init];
someButton.titleLabel.text = @"Your Button's Text";
someButton.accessibilityLabel = @"SomeNSString";
In the InterfaceBuilder -- built into XCode 4 -- you just have to select the UI item you want to have an accessibility label. The "Identity Inspector", in the "Utility"-pane, offers a textfield where you can enter any label-text you want.

bradheintz
- 3,151
- 19
- 24

0xJoKe
- 843
- 10
- 18
-
I don't see the Accessibility section in my IB - I've got Custom Class, User Defined Runtime Attributes, and Identity; but not Accessibility. – Simon Aug 28 '11 at 12:50
-
Clicking around, I can see Accessibility in most screens, but not in my MainWindow.xib - is that normal and if so, how do I set the accessibility labels there? – Simon Aug 28 '11 at 12:53
-
1I think the UIWindow-class doesn't have the accessibility-properties. It really wouldn't make sense for a window to have accessibility-variables because usually they are only used by an iPhone, if the user has enabled "VoiceOver". On an iPhone -- where only one window is possible -- it is not necessary to identify a window. Programmatically it **is** possible. – 0xJoKe Aug 28 '11 at 13:23
-
OK - Makes sense. I'm surprised I can't set it for its subviews, but I guess I can put them in separate nibs. – Simon Aug 28 '11 at 15:04