Question

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?

Was it helpful?

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

OTHER TIPS

You cannot access the internal subviews of an alert view. With iOS7, the public UIAlertView API is only used to gather information but is not actually inserted in the view hierarchy at any point. So when you modify the subviews, it goes unnoticed.

You will have to use an open-source implementation instead of the system provided one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top