Reputation: 1697
Looking at adding KIF to our app for integration testing. I'd like to be able to select a button from a UIActionSheet but it doesn't seem like there's an efficient way to set the accessibility labels on each button in the action sheet.
I'm looking at using the accessibleElementCount, iterating through the buttons that way. Is that the preferred way to do this or is there a more standard way of setting up accessibility for UIActionSheets?
Upvotes: 4
Views: 3883
Reputation: 1
If you want to have some custom control over the UIActionSheet (from a testing perspective using KIF) , the simplest way for me to do it , was replacing it with UIAlertController , if you have in mind that subclassing is not possible in both Classes , and if you test multi language app like me - you will find yourself in a trouble . You can set properties to the UIAlertAction's , here is some code , so you can have the idea :
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:[LI18n localizedString:@"YES"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Handle your yes please button action here
}];
yesButton.accessibilityLabel = @"YES_BUTTON";
Upvotes: -1
Reputation: 23271
you have must implements the UIActionSheetDelegate in your class.
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
for (UIView *_yourView in actionSheet.subviews) {
if ([_yourView isKindOfClass:[UILabel class]]) {
[((UILabel *)_yourView) setFont:[UIFont boldSystemFontOfSize:14.0f]];
}
}
}
Upvotes: 1
Reputation: 16946
From the UIKit User Interface Catalog:
Action sheets are accessible by default.
Accessibility for action sheets primarily concerns button titles. If VoiceOver is activated, it speaks the word “alert” when an action sheet is shown, then speaks its title if set (although iOS human interface guidelines recommend against titling action sheets). As the user taps a button in the action sheet, VoiceOver speaks its title and the word “button.”
From your question it's not clear if you want to change the accessibility label to something other than the button title + button, but it appears that that's not possible in a straight-forward way.
Upvotes: 4