1

my view controller has a UITextView whose attributedText I’m setting with a function that returns an NSAttributedString because a range of that string needs to be a link. I then attempt to set my accessibilityLabel to something different from that text as well as the trait to .link.

let textView = UITextView()
textView.attributedText = generateCustomAttributedText() // Contains link formatting
textView.isEditable = false
textView.isSelectable = true
textView.isScrollEnabled = false
textView.backgroundColor = .clear
textView.textContainerInset = .zero
textView.textContainer.lineFragmentPadding = 0

textView.isAccessibilityElement = true
textView.accessibilityElements = nil

textView.accessibilityLabel = "Tap to learn more about accessibility features."
textView.accessibilityTraits = .link

With this I’m expecting voiceover to read “Tap to learn more about accessibility features., Link” but instead voiceover is reading, “Tap to learn more about accessibility features., , Group”

What do I need to do to get voiceover to read my expected response?

1 Answer 1

0

From accessibilitytraits:

Combine the traits you select with the superclass’s traits. Specifically, always combine your custom traits with [super accessibilityTraits] in the method you use to set a custom element’s traits.

This means that, instead of replacing the existing traits with .link, you should do something like this:

textView.accessibilityTraits = textView.superview.accessibilityTraits.append(.link)
Sign up to request clarification or add additional context in comments.

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.