2

Does anyone know of a way to have a single value for an accessibility label span across multiple elements? I have two labels that form a single title line and the screen reader reads them separately. I have tried selecting both and applying the setting and it doesn't work.

EDIT:

Here is a view of my storyboard...

Storyboard accessibility settings

However, when the screen readers reaches this point, it reads the first label (not using the accessibility value) and then the second label.

enter image description here

2
  • hey can you post some code, screenshots? anything to explain your problem more... Commented Nov 28, 2012 at 17:21
  • Not familiar with the program you're working with, but is there a way to either combine them into one element or wrap them with one element and point the label to that? Commented Nov 29, 2012 at 14:24

3 Answers 3

2

We can group elements using UIAccessibilityElement class and provide a combined frame of the elements you want to group using accessibilityFrameInContainerSpace property.

//From Apple Docs
let profileElement = UIAccessibilityElement(accessibilityContainer: headerView)
profileElement.accessibilityLabel = profileNameLabel.text
profileElement.accessibilityValue = openPostsLabel.text
profileElement.accessibilityTraits |= UIAccessibilityTraitButton     // Tells VoiceOver to treat our new view like a button

let combinedLabelFrame = profileNameLabel.frame.union(openPostsLabel.frame)
let profileElementFrame = combinedLabelFrame.union(profileImageView.frame) //providing union of frames.
// This tells VoiceOver where the element is on screen so a user can find it as they touch around for elements
profileElement.accessibilityFrameInContainerSpace = profileElementFrame

Check apple docs Whats new in accessibility.

Link for sample app explaining how to do it.

Sign up to request clarification or add additional context in comments.

Comments

1

I had two labels in a UIStackView - so I disabled the accessibility on the actual labels and then enabled accessibility for the stack view. In Xcode 10, UIStackView does not have an "Accessibility" section in Interface Builder, so what I did is add two custom attributes under Identity Inspector > User Defined Runtime Attributes. I added a Bool named isAccessibilityElement set to true and a String named accessibilityLabel set to my desired text. Of course if you want this to update programatically, you can create an IBOutlet to the UIStackView and set the values in code.

Comments

-2

I ended up solving this issue...

I set the label value of the first element to "Transfection Search" and cleared and disabled the accessibility settings on the second. This way, the screen reader reads the first items value and completely skips the second.

It still only highlights the first element, but I don't think there is a way to group elements and apply accessibility attributes to all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.