Search code examples
iosiphoneobjective-cvoiceover

Changing the accessibility label of a button in UIAlertView - iOS


I am trying to change the accessibility label on a UIAlertView button. I saw this code online:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test"
                                            message:@"Message"
                                           delegate:nil
                                  cancelButtonTitle:@"Ok"
                                  otherButtonTitles:nil];


// In a standard UIAlertView there are 2 UILabels and some buttons
// The UILabel with the message is always the 2nd object in the array
NSArray *subviews = alert.subviews;
UILabel *messageLabel = [subviews objectAtIndex:1];
[messageLabel setAccessibilityLabel:@"Some other text"];

but it only returns the subviews of the UILabels and not the buttons (in my own case). How do i do this?


Solution

  • my suggestion is to use custom alert link

    based on apple documentation for iOS7----

    Appearance of Alert Views

    You cannot customize the appearance of alert views

    Making Alert Views Accessible

    Alert views are accessible by default.

    Accessibility for alert views pertains to the alert title, alert message, and button titles. If VoiceOver is activated, it speaks the word “alert” when an alert is shown, then speaks its title followed by its message if set. As the user taps a button, VoiceOver speaks its title and the word “button.” As the user taps a text field, VoiceOver speaks its value and “text field” or “secure text field.”

    For general information about making iOS views accessible, see Making Views Accessible